zoukankan      html  css  js  c++  java
  • NC218551 网格(dp)

    行列无关,因此对于行列分别求解

    这题的题目有个错别字,有打成由了,我做的时候没理解求的啥 ,尴尬了

    其他就是状态机dp,表示这个位置向左还是向右

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int N=2e5+10;
    const int inf=0x3f3f3f3f;
    const int mod=1e9+7;
    int n,m;
    int a[2000][2000];
    int f[1010][2];
    int cal(int x){
        int sum=x;
        while(x){
            sum+=(x%2);
            x/=2;
        }
        return sum;
    }
    int main(){
        ios::sync_with_stdio(false);
        cin>>n>>m;
        int i,j;
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++)
                cin>>a[i][j];
        }
        ll ans=0;
        for(i=1;i<=n;i++){
            f[0][1]=-1e9;
            for(j=1;j<=m;j++){
                f[j][0]=max(f[j-1][0],f[j-1][1]+cal(a[i][j-1]^a[i][j]));
                f[j][1]=max(f[j-1][0],f[j-1][1]);
            }
            ans+=max(f[m][0],f[m][1]);
            memset(f,0,sizeof f);
        }
        for(i=1;i<=m;i++){
            f[0][1]=-1e9;
            for(j=1;j<=n;j++){
                f[j][0]=max(f[j-1][0],f[j-1][1]+cal(a[j-1][i]^a[j][i]));
                f[j][1]=max(f[j-1][0],f[j-1][1]);
            }
            ans+=max(f[n][0],f[n][1]);
            memset(f,0,sizeof f);
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    把swf反编译成fla的几种方法
    隐藏tomcat页面异常显示的版本信息
    配置Tomcat-8.5 JVM内存参数
    Nim Game
    Longest Increasing Path in a Matrix
    信息熵和信息增益
    故乡的云
    urllib编码
    odd_even_list
    Different Ways to Add Parentheses
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/14443586.html
Copyright © 2011-2022 走看看