冰水挑战
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 163 Accepted Submission(s): 72
Problem Description
Polar Bear Pitching helps you crystallize your message.
The stage could not be any cooler, and we mean literally:
a hole cut through the ice in the frozen Baltic Sea.
2050有一项很有挑战的活动 —— Polar Bear Pitching 。
体验人跳入冰水中讲述自己的恐惧,改变以及梦想。这是没有时间限制的演讲,就看你能在冰水中呆多久!
现在,我们要依次面对 n 个冰水挑战,每个挑战你都可以选择接受或不接受。接受第 i 个挑战会让你丧失 ai点体力,因为每个挑战所处的环境不同,如果你要挑战它,在挑战它之前你的体力 x 会变成 min(x,bi),当你完成这个挑战的时候,你的体力会变成 x−ai,体力任何时候不允许小于等于 0,无论你是否接受第 i 个挑战,在这个挑战结束以后你的体力都会增加 ci。
现在我们想知道最多可以完成多少个挑战。
Input
第一行一个正整数 T (T≤50) 表示数据组数。
接下来 T 组数据,每组第一行两个正整数 n,c (1≤n≤103,1≤c≤109),表示挑战的数量和初始体力,接下来 n 行,每行三个非负整数 ai,bi,ci(0≤ai,bi,ci≤109)。
Output
对于每组数据输出一行一个数,表示你最多能完成几个挑战。
Sample Input
2 3 10 1 2 0 4 8 3 6 10 1 2 1 1 1 1 1 1 1
Sample Output
2 0
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e3+10;
struct node
{
ll a,b,c;
}d[maxn];
ll dp[maxn][maxn]; //前i个项目选了j个项目的最大体力
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
ll c;
scanf("%d%lld",&n,&c);
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
dp[i][j]=-1e18; //初始化-1e18
}
dp[0][0]=c;
for(int i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&d[i].a,&d[i].b,&d[i].c);
}
for(int i=1;i<=n;i++)
{
dp[i][0]=dp[i-1][0]+d[i].c; //每次都不拿的体力
for(int j=1;j<=i;j++)
{
dp[i][j]=dp[i-1][j]+d[i].c;//不拿可以得到的体力,不要忘了+c 因为这个wa了好几发
ll x=min(dp[i-1][j-1],d[i].b);
if(x>d[i].a) //拿与不拿取最大
dp[i][j]=max(dp[i][j],x-d[i].a+d[i].c);
}
}
for(int i=n;i>=0;i--)
{
if(dp[n][i]>0)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}
/*
10
4 10010
5 3
3 3 3
4 5 7
2 4 10
12 5 10
1 4 2
10 2 0
10 10 10
10 11 5
100 2 4
10
5 3
3 3 3
4 5 7
2 4 10
12 5 10
1 4 2
*/