“百度之星”资格赛 1004 度度熊的午饭时光

度度熊的午饭时光

题意。。。感觉好坑啊

题意&分析: 这是一个 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啦
AC率都不高啊

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值