标签:style blog http color os io for art
http://acm.hdu.edu.cn/showproblem.php?pid=1244
状态转移方程:dp[i][j]=max(dp[i][j-1],dp[i-1][j-a[i]]+sum[j]-sum[j-a[i]]);
dp[i][j]为第i段第j个数。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 2000 5 using namespace std; 6 7 int dp[30][maxn]; 8 int a[maxn],b[maxn],sum[maxn]; 9 int n,m; 10 11 int main() 12 { 13 while(scanf("%d",&n)!=EOF) 14 { 15 if(n==0) break; 16 scanf("%d",&m); 17 memset(a,0,sizeof(a)); 18 memset(b,0,sizeof(b)); 19 memset(dp,0,sizeof(dp)); 20 memset(sum,0,sizeof(sum)); 21 for(int i=1; i<=m; i++) 22 { 23 scanf("%d",&a[i]); 24 } 25 for(int i=1; i<=n; i++) 26 { 27 scanf("%d",&b[i]); 28 sum[i]=sum[i-1]+b[i]; 29 } 30 int len=0; 31 for(int i=1; i<=m; i++) 32 { 33 len+=a[i]; 34 for(int j=len; j<=n; j++) 35 { 36 dp[i][j]=max(dp[i][j-1],dp[i-1][j-a[i]]+sum[j]-sum[j-a[i]]); 37 } 38 } 39 printf("%d\n",dp[m][n]); 40 } 41 return 0; 42 }
hdu 1244 Max Sum Plus Plus Plus,布布扣,bubuko.com
hdu 1244 Max Sum Plus Plus Plus
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/fanminghui/p/3868775.html