It’s universally acknowledged that there’re innumerable trees in the campus of HUST.
Now HUST got a big land whose capacity is C to plant trees. We have n trees which could be plant in it. Each of the trees makes HUST beautiful which determined by the value of the tree. Also each of the trees have an area cost, it means we need to cost ci area of land to plant.
We know the cost and the value of all the trees. Now HUSTers want to maximize the value of trees which are planted in the land. Can you help them?

输入描述:

There are multiple cases.
The first line is an integer T(T≤10), which is the number of test cases.
For each test case, the first line is two number n(1≤n≤100) and C(1≤C≤108), the number of seeds and the capacity of the land.
Then next n lines, each line contains two integer ci(1≤ci≤106) and vi(1≤vi≤100), the space cost and the value of the i-th tree.

输出描述:

For each case, output one integer which means the max value of the trees that can be plant in the land.
示例1

输入

复制

1
3 10
5 10
5 10
4 12

输出

复制

22
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 105
#define mod 530600414
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 0x3f3f3f3f
int t,n,C;
int c[N],v[N];
int dp[];
int main()
{
scanf("%d",&t);
while(t--)
{ scanf("%d%d",&n,&C);
mem(dp,inf);
dp[]=;
//dp[i] 要达到价值i,需要的最小空间。
for(int i=;i<n;i++) scanf("%d%d",&c[i],&v[i]);
for(int i=;i<n;i++)
{
for(int j=;j-v[i]>=;j--){
dp[j]=min(dp[j],dp[j-v[i]]+c[i]);
}
/*
for(int j=0;j+v[i]<=10000;j++){
dp[j+v[i]]=min(dp[j+v[i]],dp[j]+c[i]);
1
3 10
5 10
5 10
4 12
dp[24]=8,因此要逆序
}
*/
}
for(int i=;i>=;i--){
if(dp[i]<=C) {
printf("%d\n",i);
break;
}
}
}
return ;
}

最新文章

  1. [转载】&mdash;&mdash;故障排除:Shared Pool优化和Library Cache Latch冲突优化 (文档 ID 1523934.1)
  2. WPF RichTextBox 做内容展示框 滚动条控制判定是否阅读完成
  3. 20个漂亮 CSS3 按钮效果及优秀的制作教程
  4. AVL树插入操作实现
  5. C#学校班级自动升级实现代码
  6. preload pic
  7. Play Framework 发现并没有热启动的特殊情况
  8. SHA-1
  9. Java中String、StringBuffer、StringBuilder和toString的介绍
  10. HTML5屏幕适配标签设置
  11. 安装setuptools和pip
  12. Palindromes&amp;nbsp;_easy&amp;nbsp;version
  13. How to get table pg_stat_user_functions.
  14. [android] 隐式意图和显式意图的使用场景
  15. redis(五)
  16. [asp.net core]The requested page cannot be accessed because the related configuration data for the page is invalid.
  17. jQuery版本的jsonp
  18. form表单序列化为json格式数据
  19. matlab入门笔记(七):数据文件I/O
  20. TDDL与Spring Boot集成Version报错——跟踪与解决

热门文章

  1. BI的意义
  2. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
  3. python+selenium之处理HTML5的视频播放
  4. 第二节 java基本语法
  5. 为什么我的C4C Service Request没办法Release到ERP?
  6. 融云红包全新升级,让App用户更便捷地用“钱”交流感情!
  7. jquery的uploadify插件实现的批量上传V3.2.1版
  8. Codeforces Round #319 (Div. 2) C Vasya and Petya&#39;s Game (数论)
  9. nginx的工作流程
  10. guruguru