zoukankan      html  css  js  c++  java
  • [NOIP2007]矩阵取数游戏

    [NOIP2007]矩阵取数游戏

    题目描述

    链接

    题解

    简单DP+毒瘤高精

    显然行与行没有关联

    所以只需要每行处理

    考虑DP i,j,k 表示第I次取数,第J行,有K次取的头的最大分数

    直接DP即可

    #include<bits/stdc++.h>
    
    using namespace std;
    
    #define LL __int128
    
    inline int read()
    {
        int f=1,x=0;
        char ch;
        do
        {
            ch=getchar();
            if(ch=='-') f=-1;
        }while(ch<'0'||ch>'9');
        do
        {
            x=(x<<3)+(x<<1)+ch-'0';
            ch=getchar();
        }while(ch>='0'&&ch<='9');
        return f*x;
    } 
    
    inline LL Pow(LL a,LL b)
    {
        LL ans=1,mul=a;
        while(b)
        {
            if(b&1) ans*=mul;
            mul*=mul;
            b>>=1;
        }
        return ans;
    }
    
    int n,m;
    int a[100 + 10][100 + 10];
    LL dp[100 + 10][100 + 10][100 + 10];
    LL ans=0;
    
    inline void print(LL x)
    {
        if(!x) return;
        if(x) print(x/10);
        putchar(x%10+'0');
    }
    
    int main()
    {
        n=read();m=read();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                a[i][j]=read();
            }
        }
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                for(int k=0;k<=i;k++)
                {
                    if(k!=0)
                    dp[i][j][k]=max(dp[i-1][j][k-1]+a[j][k]*Pow(2,i),dp[i-1][j][k]+a[j][m-(i-k)+1]*Pow(2,i));
                    else dp[i][j][k]=dp[i-1][j][k]+a[j][m-(i-k)+1]*Pow(2,i);
                }
            }
        }
        for(int j=1;j<=n;j++)
        {
            LL maxi=0;
            for(int k=0;k<=m;k++)
            {
                maxi=max(dp[m][j][k],maxi);
            //    cout<<dp[m][j][k]<<" ";
            }
        //    cout<<endl;
            ans+=maxi;
        }
           if(!ans)
        {
            cout<<0<<endl;       
        }
        else
        {
            print(ans);
        } 
    }
    /*
    2 3
    1 2 3
    3 4 2
    
    */
  • 相关阅读:
    openswitch db files
    openstack中虚拟机和其网络的联系方法 instance and network
    python操作db2和mysql ,ibm_db
    yum安装mariadb
    python 连接 db2
    db2操作 连接、备份、恢复db2
    su su
    linux 后台运行进程 fg bg ctrl+z nohup
    mysql 命令行
    IDEA-使用技巧
  • 原文地址:https://www.cnblogs.com/wlzs1432/p/11227993.html
Copyright © 2011-2022 走看看