3991. Eat or Study toj

3991.   Eat or Study
Time Limit: 1.0 Seconds    Memory Limit:65536K
Total Runs: 127    Accepted Runs:43

 




 

As a ACMer, Yan is good at arrange his schedule. On every morning of the term, he will have a choice: study or eating.
Especially, Yan can only do one thing everyday, and he have to do one thing everyday. That means Yan cannot both study and eat in one day, and he cannot do nothing on that day.If he choose study on the ith day, he will get xi knowledge points,and if he choose eating, his weight will increase yi points.After the term, Yan must face the final exam. If his knowledge points is less than m, he will fail in the exam. Now Yan wants to know the maximal value he can increase his weight without fail in the exam.

Input

The first line of input is a integer t (t≤100), means there are t test case.
For each test case, there are two integers in the first line, n(n≤100)  and m(m≤100). n means there are n days in the term. m means that Yan have to get m knowledges when he face the final exam, or he will fail.Then n lines follow, each line contains two integer, xi(0≤xi≤100) and yi(0≤yi≤100).  xi means he will get  xi knowledge points if he study in the ith day, yi means he will get yi weight points if he eats in the ith day.

Output

For each test case, there is only one line.
If Yan can pass the exam, output the max weight he can increase without fail.
If Yan can't pass the exam, output "JUMP DOWN!"

Sample Input

3
2 3
3 2
3 3
3 10
3 2
3 3
3 3
3 5
2 10
2 100
2 50

Sample Output

3
JUMP DOWN!
0

dp[i]表示能满足i点知识点的情况下取得最小的重量

大侠的代码

 

#include<cstdio>
#include<iostream>
using namespace std;
#define INF 100001
int main()
{
	int t;
	int x[150],y[150];
	int dp[150];
	cin>>t;
	while(t--)
	{
		int n,m;
		int ans=0;
		cin>>n>>m;
		for(int i=0;i<=m;i++)
			dp[i]=INF;
		for(int i=0;i<n;i++)
		{
			cin>>x[i]>>y[i];
			ans+=y[i];		
		}
		for(int i=0;i<n;i++)
			for(int j=m;j>=0;j--)
				if(j-x[i]<=0)
					dp[j]=min(dp[j],y[i]);
				else
					dp[j]=min(dp[j],dp[j-x[i]]+y[i]);
		if(dp[m]<INF)
			cout<<(ans-dp[m])<<endl;
		else
			cout<<"JUMP DOWN!"<<endl;
	}
	return 0;
}


 

 错误代码 还没找出哪里错

#include<cstdio>
#include<iostream>
using namespace std;
#define INF 100001
int main()
{
	int t;
	int x[150],y[150];
	int dp[15000];
	cin>>t;
	while(t--)
	{
		int n,m;
		int ans=0;
		int sum=0;
		cin>>n>>m;
		for(int i=0;i<n;i++)
		{
			cin>>x[i]>>y[i];
			ans+=y[i];
			sum+=x[i];		
		}
		for(int i=0;i<=sum;i++)
			dp[i]=INF;
		dp[0]=0;
		for(int i=0;i<n;i++)
			for(int j=sum;j>=x[i];j--)
				if(dp[j-x[i]]<INF)
					dp[j]=min(dp[j],dp[j-x[i]]+y[i]);
		int flag=1;
		for(int i=m;i<=sum;i++)
			if(dp[i]<=ans)
			{
				flag=0;
				cout<<(ans-dp[i])<<endl;
				break;
			}
		if(flag)
			cout<<"JUMP DOWN!"<<endl;
	}
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值