您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: