度度熊的午饭时光
题意。。。感觉好坑啊
题意&分析: 这是一个 0 1背包问题,只不过要求菜品得分尽可能的高,菜品序号和尽可能的小,同时价格尽量低。好奇怪有没有!!!我也是很神奇的就A出来啦。题意不清且不严谨,数据很水的样子,只需要利用最后的dp结果逆推价格就可以了过了,兴许出题人的思路我没有跟上吧,感觉题目的标程是有bug的,求出来的并不是最优解。有组数据很有问题。
数据如下:
1
138
8
58 49
81 68
28 46
74 20
14 58
62 14
56 39
35 54
代码如下:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cctype>
#include <fstream>
#define INF 0x3f3f3f3f
#define TEST cout<<"stop here"<<endl
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
struct meal{
int score,cost;
}a[110];
bool ans[110];
int dp[1010];
bool vis[110][1010];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int T,kase=1;
cin>> T;
while(T--){
int b,n;
cin>>b>>n;
for(int i=1;i<=n;i++)
cin>>a[i].score>>a[i].cost;
memset(dp,0,sizeof(dp));
memset(vis,false,sizeof(vis));
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++){
for(int j=b;j>=0;j--){
if(j>=a[i].cost){
if(dp[j] < dp[j-a[i].cost] + a[i].score){
dp[j] = dp[j-a[i].cost] + a[i].score;
vis[i][j] = true;
}
else vis[i][j] = false;
}
}
}
int p=b,cnt = 0;
for(int i=n;i>=1;i--){
if(vis[i][p]){
ans[i]=true;
p -= a[i].cost;
cnt++;
}
}
int ANS = 0;
for(int i=1;i<=n;i++){
if(ans[i])
ANS += a[i].cost;
}
printf("Case #%d:\n",kase++);
printf("%d %d\n",dp[b],ANS);
for (int i = 1; i <= n; i++)
if (ans[i])
printf("%d%c", i, (--cnt == 0) ? '\n' : ' ');
}
return 0;
}
return 0;
}
AC啦