简单的DP!求最大不连续子序列和,递推式也是很简单
dp[i] = max(dp[i-2]+a[i],dp[i-1]);
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <queue>
#include <stack>
using namespace std;
int vol[200010],row[200010],dp[200010];
int main()
{
int n,m,i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i = 1;i <= n;i ++)
{
for(j = 1;j <= m;j ++)
{
scanf("%d",&row[j]);
}
dp[0] = 0;
dp[1] = row[1];
for(j = 2;j <= m;j ++)
{
dp[j] = max(dp[j-1],dp[j-2] + row[j]);
}
vol[i] = dp[m];
}
dp[0] = 0;
dp[1] = vol[1];
for(j = 2;j <= n;j ++)
{
dp[j] = max(dp[j-1],dp[j-2] + vol[j]);
}
printf("%d\n",dp[n]);
}
}