Beautiful Land(超大容量背包)


Beautiful Land

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

It’s universally acknowledged that there’re innumerabletrees in the campus of HUST.
Now HUST got a big land whose capacity is C to plant trees. We have n treeswhich could be plant in it. Each of the trees makes HUST beautiful whichdetermined 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 maximizethe 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 thei-th tree.

输出描述:

For each case, output one integer which means the maxvalue of the trees that can be plant in the land.

示例1

输入

1

3 10

5 10

5 10

4 12

输出

22

 

/*最大价值对应最小容量*/

 

///#include

#include

#include

#include

#include

#define ll long long

#define MT(a,b) memset(a,0,sizeof(a));

using namespace std;

 

const int maxn = 1e4 + 5;

 

int main()

{

       intT; cin >> T;

       while(T--)

       {

              intdp[10005];

              MT(dp,0);

              intn, c;

              cin>> n >> c;

              intw[maxn], v[maxn];

              intsum_w = 0, sum_v = 0;

              for(int i = 0; i> w[i] >> v[i];

                     sum_w+= w[i];

                     sum_v+= v[i];

              }

              if(sum_w <= c)

              {

                     cout<< sum_v << endl;

                     continue;

              }

              dp[sum_v]= sum_w;

              for(int i = 0; i < sum_v; i++)

                     dp[i]= INT_MAX;

              for(int i = 0; i=0&&dp[j]-w[i]>=0)

                            dp[j-v[i]]= min(dp[j]-w[i], dp[j - v[i]]);

                     }

              }

              for(int i = sum_v; i >= 0; i--)

                     if(dp[i] <= c)

                     {

                            cout<< i << endl;

                            break;

                     }

       }

       return0;

}




你可能感兴趣的:(Beautiful Land(超大容量背包))