Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
自己做出来的第一个背包,正式开始吭DP了。顺便ORZ 0ms的大神……#include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<queue> #include<map> #include<stack> #include<iostream> #include<list> #include<set> #include<cmath> #define INF 0x7fffffff #define eps 1e-6 using namespace std; int dp[1000001]; int c[100001],v[100001]; int n,m; int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) scanf("%d%d",&c[i],&v[i]); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=m;j-c[i]>=0;j--) { dp[j]=max(dp[j],dp[j-c[i]]+v[i]); } } int ans=0; for(int i=0;i<=m;i++) ans=max(ans,dp[i]); printf("%d\n",ans); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator