• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 3 [D] Fundraised

你为何这么叼!

[D] Fundraised

 

Guess what?! Dalia won the money (an amount X), and now it’s time to spend it. Mohamed Fouad is the deputy regional contest director and he wants to spend the money but he doesn’t know what to spend it on. There are N items that he can buy like name-tags, T-shirts, helium balloons, trophies, etc. each having a different importance value and a cost to buy one unit from (you can buy as much units of any item as you want as long as you don't exceed the budget). 
Mohamed wants your help; tell him the maximum importance value he can get after he chooses optimally to buy any number of items without exceeding his budget.  


Input Specification
The first line of input contains an integer T, the number of test cases. T test cases follow, the first line of each test case contains two integers (1 <= N <= 100), (1<= X <= 10000). The second line of the test case contains N space separated integers Ii (1<=Ii<=400000), each representing the importance value Fouad earns from item i (0 <= i < N). The following line contains N space separated integers Ci (1<= Ci <=1000), each representing the cost of an item i (0 <= i < N). 


Output Specification
For each test case, on a separate line, output the maximum importance value Fouad can get. 


Sample Input
1

5 20

1 2 3 4 5

2 6 3 5 4 


Sample Output
25

 

 1 #include <cstdio>
 2 #include <vector>
 3 #include <cstring>
 4 #include <queue>
 5 #include <algorithm>
 6 using namespace std;
 7 #define maxn 10005
 8 #define mod 1000000007
 9 #define ll long long
10 int n,m,s;
11 ll dp[maxn];
12 ll a[maxn],b[maxn];
13 int main(){
14     int t;
15     scanf("%d",&t);
16     while(t--){
17         scanf("%d%d",&n,&s);
18         memset(dp,0,sizeof dp);
19         for(int i=0;i<n;i++)scanf("%I64d",&b[i]);
20         for(int i=0;i<n;i++)scanf("%I64d",&a[i]);
21         for(int i=0;i<n;i++)
22             for(int j=a[i];j<=s;j++)
23                 if(dp[j]<dp[j-a[i]]+b[i])dp[j]=dp[j-a[i]]+b[i];
24         printf("%I64d\n",dp[s]);
25     }
26     return 0;
27 }
View Code 2013-10-07 22:15:17 

 

posted @ 2013-10-07 22:17  HaibaraAi  阅读(134)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3