http://acm.hdu.edu.cn/showproblem.php?pid=2159
2013-04-04 16:12
627 查看
/* 二维背包: 忍耐度 与 怪的数量 dp[i][j]=max(dp[i][j],dp[i-v][j-k]+val[v]); i代表忍耐度,j代表杀怪的数目,dp[i][j]代表获得的经验值。 */ #include<iostream> #include<algorithm> #include<cstdio> #include<string.h> using namespace std; int dp[111][111]; int val[111],wei[111]; int n,m,k,s; int a,b; int max(int a,int b) { return a>b?a:b; } int main() { int ans; while(scanf("%d%d%d%d",&n,&m,&k,&s)!=EOF) { ans=-1; for(int i=0; i<k; i++) { scanf("%d%d",&val[i],&wei[i]); } memset(dp,0,sizeof(dp)); for(int i=0; i<k; i++) //代表有i中怪物 for(int j=wei[i]; j<=m; j++) //打怪时的忍耐度 for(int k=1; k<=s; k++) //代表最多打怪的数目 { dp[j][k]=max(dp[j][k],dp[j-wei[i]][k-1]+val[i]); } for(int j=0; j<=m; j++)//打怪时的忍耐度 if(dp[j][s]>=n) { ans=j; break; } if(ans==-1) printf("-1\n"); else printf("%d\n",m-ans); } return 0; }
相关文章推荐
- http://acm.hdu.edu.cn/showproblem.php?pid=1709
- http://acm.hdu.edu.cn/showproblem.php?pid=2602
- http://acm.hdu.edu.cn/showproblem.php?pid=2516
- http://acm.hdu.edu.cn/showproblem.php?pid=1542 矩形面积的并 线段树 + 扫描线 + 离散化
- Robberies&&http://acm.hdu.edu.cn/showproblem.php?pid=2955
- http://acm.hdu.edu.cn/showproblem.php?pid=2066&&多源多点
- 确定比赛名次(http://acm.hdu.edu.cn/showproblem.php?pid=1285)
- http://acm.hdu.edu.cn/showproblem.php?pid=2871&&Memory Control
- http://acm.hdu.edu.cn/showproblem.php?pid=1394&&线段树之求逆序数
- http://acm.hdu.edu.cn/showproblem.php?pid=1039..借鉴了别人的一些方法。。
- http://acm.hdu.edu.cn/showproblem.php?pid=1686
- A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570
- http://acm.hdu.edu.cn/showproblem.php?pid=3371
- http://acm.hdu.edu.cn/showproblem.php?pid=3342&&拓扑入门题
- 树状数组&&http://acm.hdu.edu.cn/showproblem.php?pid=1556
- http://acm.hdu.edu.cn/showproblem.php?pid=2838&&逆序数的应用
- http://acm.hdu.edu.cn/showproblem.php?pid=2688&&树状数组求正序数
- Text Reverse&&http://acm.hdu.edu.cn/showproblem.php?pid=1062
- http://acm.hdu.edu.cn/showproblem.php?pid=1010
- 分拆素数和(http://acm.hdu.edu.cn/showproblem.php?pid=2098)