ZOJ 3703 Happy Programming Contest(DP)
输出路径,搞了一个DFS出来,主要是这里,浪费了好长时间。
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int dp[][];
int c[],v[],que[];
int maxz,ti;
void dfs(int n,int T,int step)
{
int i,t1,t2;
if(n == )
{
if(maxz < step)
{
maxz = step;
sort(que,que+step);
t1 = t2 = ;
for(i = ;i < step;i ++)
{
t1 += que[i];
t2 += t1;
}
ti = t2;
}
else if(maxz == step)
{
sort(que,que+step);
t1 = t2 = ;
for(i = ;i < step;i ++)
{
t1 += que[i];
t2 += t1;
}
ti = min(t2,ti);
}
return ;
}
if(dp[n][T] == dp[n-][T])
dfs(n-,T,step);
if(T >= c[n]&&dp[n][T] == dp[n-][T-c[n]] + v[n])
{
que[step] = c[n];
dfs(n-,T-c[n],step+);
}
return ;
}
int main()
{
int cas,T,n,i,j;
scanf("%d",&cas);
while(cas--)
{
memset(dp,,sizeof(dp));
scanf("%d%d",&T,&n);
for(i = ;i <= n;i ++)
scanf("%d",&c[i]);
for(i = ;i <= n;i ++)
scanf("%d",&v[i]);
for(i = ;i <= n;i ++)
{
for(j = ;j <= T;j ++)
{
if(j >= c[i])
dp[i][j] = max(dp[i-][j],dp[i-][j-c[i]]+v[i]);
else
dp[i][j] = dp[i-][j];
}
}
maxz = ;
dfs(n,T,);
printf("%d %d %d\n",dp[n][T],maxz,ti);
}
return ;
}
ZOJ 3703 Happy Programming Contest(DP)的更多相关文章
- ZOJ 3703 Happy Programming Contest(0-1背包)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...
- ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2017)- K. Poor Ramzi -dp+记忆化搜索
ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2017)- K. ...
- 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp
2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502 The 12th Zhejiang Provincial ...
随机推荐
- saltapi中expr_form参数的使用
以前,一直用compound参数, 现在,想要并行执行salt命令,那list就派上用场了. 同时传多个主机列表,用逗号分隔,然后,用list参数传,就好. [root@c1773 deployop] ...
- 算法系列:HMM
隐马尔可夫(HMM)好讲,简单易懂不好讲. 用最经典的例子,掷骰子.假设我手里有三个不同的骰子.第一个骰子是我们平常见的骰子(称这个骰子为D6),6个面,每个面(1,2,3,4,5,6)出现的概率是1 ...
- wp8 入门到精通 ---转换
/// <summary> /// 颜色字符串转Color /// </summary> public static ...
- usb设备驱动描述,王明学learn
usb设备驱动 本章主要内容包含以下:USB总线介绍,USB协议分析,USB系统架构 一.USB总线介绍 1.1USB发展史 USB(Universal Serial Bus)通用串行总线,是一种外部 ...
- Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构
分享两篇Win 10应用开发的XML文档结构:Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构. Win 10 开发中Adapt ...
- 智能车学习(七)——按键矩阵的实现
一.原理说明 就是按键矩阵代码书写的一个说明,就是讲K5到K7先输出高电平,而K1和K4则调成上拉输入,如果检测到K1到K4有一个变为0,说明有按键按下去,立刻进行转换,是的K1到K4设置为输出高电平 ...
- JQuery经典小例子——可编辑的表格
可编辑的表格: 屏幕剪辑的捕获时间: 2015/8/14 9:16 HTML代码为: <!DOCTYPE html> <htmlxmlns="http://www.w3.o ...
- Linux sed 批量替换多个文件中的字符串
sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir` 例如:替换/home下所有文件中的www.bcak.co ...
- JavaScript 之 document对象
对象属性document.title //设置文档标题等价于HTML的title标签document.bgColor //设置页面背景色document.fgColor //设置前景色(文本颜色)do ...
- php,blade语法
打印数组 <?php print_r($agreement);die?> <?= ?><?php echo ?><?php printf();die;?> ...