第十四届华中科技大学程序设计竞赛决赛同步赛 Beautiful Land

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



复制代码
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <vector>
 5 #include <cmath>
 6 #include <algorithm>
 7 using namespace std;
 8 #define N  105
 9 #define mod 530600414
10 #define mem(a,b) memset(a,b,sizeof(a))
11 #define ll  long long 
12 #define inf 0x3f3f3f3f
13 int t,n,C;
14 int c[N],v[N];
15 int dp[10010];
16 int main()
17 {
18     scanf("%d",&t);
19     while(t--)
20     {   scanf("%d%d",&n,&C);
21         mem(dp,inf);
22         dp[0]=0;
23         //dp[i] 要达到价值i,需要的最小空间。
24         for(int i=0;i<n;i++)  scanf("%d%d",&c[i],&v[i]);
25         for(int i=0;i<n;i++)
26         {
27             for(int  j=10000;j-v[i]>=0;j--){
28                 dp[j]=min(dp[j],dp[j-v[i]]+c[i]);
29             }
30             /*
31             for(int  j=0;j+v[i]<=10000;j++){
32                 dp[j+v[i]]=min(dp[j+v[i]],dp[j]+c[i]);
33                 1
34                 3 10
35                 5 10
36                 5 10
37                 4 12
38                 dp[24]=8,因此要逆序
39             }
40             */
41         }
42         for(int i=10000;i>=0;i--){
43             if(dp[i]<=C) {
44                 printf("%d\n",i);
45                 break;
46             }
47         }
48     }
49     return  0;
50 }
复制代码

 

posted on   cltt  阅读(137)  评论(0编辑  收藏  举报

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示