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 ;
}

第十四届华中科技大学程序设计竞赛决赛同步赛 Beautiful Land的更多相关文章

  1. 第十四届华中科技大学程序设计竞赛决赛同步赛 A - Beauty of Trees

    A - Beauty of Trees 题意: 链接:https://www.nowcoder.com/acm/contest/119/A来源:牛客网 Beauty of Trees 时间限制:C/C ...

  2. 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)

    链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...

  3. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

  4. 第十四届华中科技大学程序设计竞赛 C Professional Manager【并查集删除/虚点】

    题目描述 It's universally acknowledged that there're innumerable trees in the campus of HUST. Thus a pro ...

  5. 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】

    链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  6. 第十四届华中科技大学程序设计竞赛 J Various Tree【数值型一维BFS/最小步数】

    链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  7. 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】

    链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  8. 第十四届华中科技大学程序设计竞赛 K--Walking in the Forest

    链接:https://www.nowcoder.com/acm/contest/106/K来源:牛客网 题目描述 It’s universally acknowledged that there’re ...

  9. 第十四届华中科技大学程序设计竞赛--J Various Tree

    链接:https://www.nowcoder.com/acm/contest/106/J来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

随机推荐

  1. 079 Word Search 单词搜索

    给定一个二维面板和一个单词,找出该单词是否存在于网格中.这个词可由顺序相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单元格内的字母不允许被重复使用.例如,给定 二 ...

  2. openstack安装newton版本neutron服务部署(四)

    一.管理节点部署服务: 1.安装neutron: [root@linux-node1 ~]# yum install openstack-neutron openstack-neutron-ml2 o ...

  3. 在Eclipse下搭建Hadoop开发环境

    在前面的博文中博主展示了如何在虚拟机中搭建Hadoop的单节点伪分布集群,今天给大家介绍一下如何在Eclipse环境中搭建Hadoop的管理和开发环境,话不多说,下面我们就进入正题吧! 1.JDK安装 ...

  4. EF 记录执行的sql语句

    最近做了个中等的项目,数据不会很多,开发时间比较紧迫,所以用了EF的框架. 在使用过程中,发现有时候执行的结果不如预期,想看看执行的sql语句为何,遍查找资料,在网上找到了相关辅助类,拿来使用,部署到 ...

  5. jsp使用中$的符号使用失效

    解决方法 添加一段话  <%@ page isELIgnored="false"%> 原因:因为jsp servlet版本问题,2.3及2.3之前的版本isELIgno ...

  6. hard link && symbolic link

    hard link :硬连接,多了一个inode,指向原始的inode,通过这个硬连接删除文件,文件不会被真正删除,而是删除这个inode symolic link:符号连接相当于快捷方式

  7. Css Hack 大全(IE6、IE7、IE8、IE9 css hack)

    一.IE6 css hack: 1. *html Selector {} /* Selector 表示 css选择器 下同 */ 2. Selector { _property: value; } / ...

  8. Git基础使用教程(仓库初始化,源码clone,源码push)

    一.下载Git源码管理客户端 Git下载地址:https://git-scm.com/ 二.检查电脑是否已安装Git 1)已安装:输入git出现下图提示则代表已安装成功. 2)未安装情况下git会出现 ...

  9. 初识Spinner

    Spinner是个下拉列表框,与listview一样,也是adapterView的一个间接子类,是一个显示数据的窗口. <Spinner android:id="@+id/spinne ...

  10. POJ 2184 Cow Exhibition 奶牛展(01背包,变形)

    题意:有只奶牛要证明奶牛不笨,所以要带一些奶牛伙伴去证明自己.牛有智商和幽默感,两者可为负的(难在这),要求所有牛的智商和之 / 幽默感之和都不为负.求两者之和的最大值. 思路:每只牛可以带或不带上, ...