标签:blog http os io for 2014 log ios
#include <iostream>
#include <string.h>
using namespace std;
int dp[105][1005], w[105],v[105],T,M;
int max(int x,int y){ return x>y?x:y; }
void f( )
{ int i,j;
for (i=1; i<=M; i++)
for (j=0;j<=T; j++)
{ if (i==0) dp[i][j]=0;
else dp[i][j]=dp[i-1][j];
if (j>=w[i]) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
}
}
int main()
{ int i;
cin>>T>>M;
for ( i=1; i<=M; i++) cin>>w[i]>>v[i];
f( );
cout<<dp[M][T]<<endl;
return 0;
}
*********************************************************************************************
#include <iostream>
#include <string.h>
using namespace std;
int dp[105][1005], w[105],v[105],T,M;
int max(int a,int b) { return a > b ? a : b; }
void f( )
{ int i,j;
for (i=1; i<=M; i++)
for (j=0;j<=T; j++)
{ if (i==0) dp[i][j]=0;
else dp[i][j]=dp[i-1][j];
if (j>=w[i]) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
}
}
int main()
{ int i;
cin>>T>>M;
for ( i=1; i<=M; i++) cin>>w[i]>>v[i];
f( );
cout<<dp[M][T]<<endl;
return 0;
}
(RQoj 15 采药------rwkj 10.1.5.253 1447) 动态规划 DP 1,布布扣,bubuko.com
(RQoj 15 采药------rwkj 10.1.5.253 1447) 动态规划 DP 1
标签:blog http os io for 2014 log ios
原文地址:http://www.cnblogs.com/2014acm/p/3908349.html