pipioj 1022: 淘金(简单dp)
http://www.pipioj.online/problem.php?id=1022
1 #define IO std::ios::sync_with_stdio(0); 2 #define bug(x) cout<<#x<<" is "<<x<<endl 3 #include <bits/stdc++.h> 4 #define iter ::iterator 5 using namespace std; 6 typedef long long ll; 7 typedef pair<int,ll>P; 8 #define pb push_back 9 #define mk make_pair 10 #define se second 11 #define fi first 12 #define rs o*2+1 13 #define ls o*2 14 const ll mod=1e9+7; 15 const int N=2e2+5; 16 int T,n,m; 17 int a[N][N]; 18 int d[N],f[N],e[N]; 19 int main(){ 20 while(~scanf("%d%d",&n,&m)){ 21 for(int i=1;i<=n;i++){ 22 for(int j=1;j<=m;j++){ 23 scanf("%d",&a[i][j]); 24 } 25 d[1]=a[i][1]; 26 for(int j=2;j<=m;j++){ 27 d[j]=max(d[j-2]+a[i][j],d[j-1]); 28 } 29 f[i]=d[m]; 30 } 31 int ans=0; 32 e[1]=f[1]; 33 for(int i=2;i<=n;i++){ 34 e[i]=max(e[i-1],e[i-2]+f[i]); 35 } 36 printf("%d\n",e[n]); 37 } 38 }