前言:这个不会,想了半天没做出来,问的同学,人家一个优化算法甩我脸上,现在自闭了
让人头疼的“双十一”
双十一就这样轰轰烈烈的来了,网购宅男小明磨拳霍霍!理想是丰满的,现实是骨感的。小明虽然在购物车添加了不少物品,但是他低头看了下口袋却是叹声连连。小明想要购买的商品中,每件商品都有其价格和期待值,小明只能利用有限的资金,购买能让自己期待值总和达到最大的一系列物品了。
输入格式:
第一行一个整数T表示有T组测试数据(T<=50)。
接下来的T组测试数据:
第一行包含两个整数N和M,N表示小明有多少钱,M表示有多少件物品(1<=M<=100)。
再二行包含M个整数,表示对应每个物品的价格。
第三行包含M个整数,表示小明对每个物品的期待值。
其中,小明兜里的钱N、每个物品的价格、每个物品的期待值的值域均为(0, 3000)。
输出格式:
每组样例一行,输出最大期待值的总和。假设第i组样例最大期待值为e,则输出格式为“Case #i: e”
输入样例:
4
10 5
2 3 7 7 3
4 3 5 6 4
10 8
5 6 4 2 3 7 1 8
5 3 5 3 5 7 5 7
20 7
10 15 4 5 6 8 5
15 14 9 2 2 6 7
10 3
7 4 5
16 7 10
输出样例:
Case #1: 11
Case #2: 18
Case #3: 31
Case #4: 17
CODE:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+7;
using namespace std;
#define ARR_SIZE 10001
#define Num 500005
#define N 5005
int money,num;
int a[N],b[N],dp[N][N];
int main(){
int T;
cin>>T;
for(int turn = 0; turn < T; turn++){
cin>>money>>num;
for(int i = 1; i <= num; i++){
cin>>a[i];
}
for(int i = 1; i <= num; i++){
cin>>b[i];
}
// memset(dp,0,sizeof(dp));
for(int i = 1; i <= num; i++){
for(int j = money; j >= 0; j--){
if(j >= a[i]){
dp[i][j] = max(dp[i-1][j-a[i]] + b[i],dp[i-1][j]);
}
else{
dp[i][j] = dp[i-1][j];
}
}
}
cout<<"Case #"<<turn+1<<": "<<dp[num][money]<<endl;
}
}