http://acm.hdu.edu.cn/showproblem.php?pid=6083

题意:

思路:

01背包+路径记录。

题目有点坑,我一开始逆序枚举菜品,然后一直WA,可能这样的话路径记录会有点问题。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n, m;
int val[],w[];
int d[];
int path[][];
vector<int> ans; int main()
{
//freopen("in.txt","r",stdin);
int kase=;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
scanf("%d",&m);
for(int i=;i<=m;i++) scanf("%d%d",&val[i],&w[i]);
memset(d,,sizeof(d));
memset(path,,sizeof(path)); for(int i=;i<=m;i++)
{
for(int j=n;j>=w[i];j--)
{
if(d[j-w[i]]+val[i]>d[j])
{
d[j]=d[j-w[i]]+val[i];
path[i][j]=;
}
}
}
printf("Case #%d:\n",++kase);
int sum=;
ans.clear();
for(int i=m,j=n;i>= && j>=;i--)
{
if(path[i][j])
{
ans.push_back(i);
j-=w[i];
sum+=w[i];
}
}
printf("%d %d\n",d[n],sum);
sort(ans.begin(),ans.end());
int sz=ans.size();
for(int i=;i<sz;i++)
{
printf("%d%c",ans[i],i==sz-?'\n':' ');
}
}
return ;
}

HDU 6083 度度熊的午饭时光(01背包+记录路径)的更多相关文章

  1. 百度之星资格赛 1004 度度熊的午饭时光(01背包+最小序号和+字典序+有bug)

    分析 首先声明一下,我的代码有漏洞的,求大神给个正确代码 思路如下: 首先做一遍01背包记录路径并求出最大总分,令path[i][j]表示第i个物品包含在dp[j]的求值过程中.再逆序枚举money, ...

  2. UVA624(01背包记录路径)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. 01背包记录路径 (例题 L3-001 凑零钱 (30分))

    题意: 就是找出来一个字典序最小的硬币集合,且这个硬币集合里面所有硬币的值的和等于题目中的M 题解: 01背包加一下记录路径,如果1硬币不止一个,那我们也不采用多重背包的方式,把每一个1硬币当成一个独 ...

  4. HDU - 6082 度度熊与邪恶大魔王(背包变式)

    度度熊与邪恶大魔王 度度熊为了拯救可爱的公主,于是与邪恶大魔王战斗起来. 邪恶大魔王的麾下有n个怪兽,每个怪兽有a[i]的生命值,以及b[i]的防御力. 度度熊一共拥有m种攻击方式,第i种攻击方式,需 ...

  5. 牛客网暑期ACM多校训练营(第三场) A PACM Team 01背包 记录路径

    链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 Eddy was a contestant participating in ACM ICPC ...

  6. UVA 624(01背包记录路径)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. Atcoder Beginner Contest145E(01背包记录路径)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[3007],b[3007];int ...

  8. hdu 2126 Buy the souvenirs 二维01背包方案总数

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. Codeforces Gym-102219 2019 ICPC Malaysia National E. Optimal Slots(01背包+输出路径)

    题意:给你一个体积为\(T\)的背包,有\(n\)个物品,每个物品的价值和体积都是是\(a_{i}\),求放哪几个物品使得总价值最大,输出它们,并且输出价值的最大值. 题解:其实就是一个01背包输出路 ...

随机推荐

  1. 去掉UITableView多余的分割线

    UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];

  2. HTML <input> 标签的 name 属性

    定义和用法 name 属性规定 input 元素的名称. name 属性用于对提交到服务器后的表单数据进行标识,或者在客户端通过 JavaScript 引用表单数据. 注释:只有设置了 name 属性 ...

  3. [LeetCode] 827. Making A Large Island

    In a 2D grid of 0s and 1s, we change at most one 0 to a 1. After, what is the size of the largest is ...

  4. PostgreSQL远程连接配置

    postgresql默认情况下,远程访问不能成功,如果需要允许远程访问,需要修改两个配置文件,说明如下: 1.postgresql.conf 将该文件中的listen_addresses项值设定为“* ...

  5. js五星好评2

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Mysql的group by语句

    如上图查询结果,因为group by后面的字段是的分组的依据字段,所以select子句中只有是group by后面的字段,或者是聚集函数才有意义.然而mysql居然可以在select子句中出现不在gr ...

  7. nginx安装,反向代理配置

    1.centos 版本 下载最新稳定版 https://www.nginx.com/resources/wiki/start/topics/tutorials/install/# 2.执行语句: ./ ...

  8. lnmp之阿里云源码安装mysql5.7.17

    mysql5.7.17一直号称世界上最好的mysql 那么就在阿里云主机linux安装它(采用的源码安装mysql5.7.17) 我在阿里云主机上安装它 连接阿里云主机 进入,跟我们自己装的虚拟机一毛 ...

  9. 【Redis学习之二】Redis:redis.conf 配置详解

    参数说明redis.conf 配置项说明如下:1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程  daemonize no2. 当Redis以守护进程方式运行 ...

  10. Linux虚拟机克隆后网卡UUID问题

    虚拟机中的Linux系统克隆后,网卡配置eth0中的UUID可被克隆的系统是一样的,这样UUID就失去了唯一性. 我参考了该篇博客: 有时我们不小心将/etc/sysconfig/network-sc ...