HDU 3496 Watch The Movie
2016-06-14 11:39
337 查看
题目分析
这道题毒很深,因为前一题写的也是2维背包,写到这一题直接就把状态转移方程写出来了,但是一直wa到死,完全不知道为什么!!后来看了一下别人的博客,博客上说有可能价值为负数!!我就呵呵哒,我在想这个女孩中毒不浅呀!!自己不喜欢的也列出来让她uncle买!!于是把初始化给改了就过了!!。#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 105; const int INF = 0x3f3f3f3f; int V[maxn],T[maxn]; int dp[1005][105]; int main() { int t; scanf("%d", &t); while(t--) { int N,M,L; scanf("%d %d %d", &N, &M, &L); for(int i = 1; i <= N; i++) scanf("%d %d", &T[i], &V[i]); memset(dp, 0, sizeof(dp)); for(int i = 0; i <= L; i++) for(int j = 0; j <= M; j++) if(j == 0) dp[i][j] = 0; else dp[i][j] = -INF; for(int i = 1; i <= N; i++) for(int j = L; j >= T[i]; j--) for(int k = 1; k <= M; k++) dp[j][k] = max(dp[j][k], dp[j-T[i]][k-1] + V[i]); if(dp[L][M] < 0) dp[L][M] = 0; printf("%d\n", dp[L][M]); } return 0; }
相关文章推荐
- 触发器new和old的用法区别
- 【LeetCode】260. Single Number III
- Android UDP连接发送请求和接受请求的例子
- Struts2-初始化
- Apache HTTP Server 与 Tomcat 的三种连接方式介绍
- Python 情感分析
- Oracle用Loop循环实现大量CRUD操作
- DOS 的历史
- js性能优化原理
- 必须知道的20个正则表达式
- Catalan number
- Linux内核与根文件系统的关系
- Win10系统下软件UI显示不完整解决方案
- javascript之函数节流
- uploadify 上传 500错误
- 枚举排列问题
- SpringMVC xml的配置写法
- Android与JS互相调用
- C语言for循环、while循环(含math.h)
- iOS 圆角那些事