hdu3496(二维背包问题)
2015-08-24 15:38
246 查看
题意:在N张CD中选M张出来,且选中CD播放时间总和不超过L。使喜欢度总和最大。
分析:简单二维01背包
分析:简单二维01背包
#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std; int dp[102][1002]; int main(){ int T;scanf("%d",&T); while(T--){ int N,M,L;scanf("%d%d%d",&N,&M,&L); memset(dp,-1,sizeof(dp)); for(int i=0;i<=L;i++) dp[0][i]=0; for(int i=0;i<N;i++) { int time,value; scanf("%d%d",&time,&value); for(int j=M;j>=1;j--) for(int k=L;k>=time;k--) dp[j][k]=max(dp[j][k],dp[j-1][k-time]+value); }//for if(dp[M][L]<0) printf("0\n"); else printf("%d\n",dp[M][L]); } return 0; }
相关文章推荐
- hdoj 5137 How Many Maos Does the Guanxi Worth 【最短路 + 删点】
- GOOGLE校招的笔试题解析
- IOS的socket开发基础
- [LeedCode OJ]#232 Implement Queue using Stacks
- [iOS开发日记]简易计算器
- Iphone程序运行流程
- Caliburn Micro Part 5: The Window Manager
- 多网卡绑定
- hessian spring 调用
- Android 打包签名(一)
- [LeedCode OJ]#231 Power of Two
- Windows系统,Visual Studio 2010安装MPICH2
- [转] thrift的使用介绍
- 9.11练习:文件访问,写一个逐页显示文本文件的程序,提示输入一个文件名,每次显示文本文件的25行,暂停并向用户提示“按任意键继续”,按键后继续执行。
- Linux软连接和硬链接
- 求解 org.elasticsearch.index.mapper.MapperParsingException
- Spring Security + Hibernate XML Example
- jquery+CSS实现的多级竖向展开树形TRee菜单效果
- 淘宝美工设计师细说何为天猫透明背景
- Caliburn Micro Part 4: The Event Aggregator