题目链接

输出路径,搞了一个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)的更多相关文章

  1. ZOJ 3703 Happy Programming Contest(0-1背包)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...

  2. ZOJ 3703 Happy Programming Contest

    偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 ...

  3. 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 ...

  4. 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. ...

  5. 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 ...

  6. 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 ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...

  9. 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 ...

随机推荐

  1. Genymotion刷入谷歌应用市场以及获取root权限

    Genymotion刷入谷歌应用市场以及获取root权限 - 推酷http://www.tuicool.com/articles/rEV3aa6 刷入gapp, arm框架,supersu的包要注意, ...

  2. OCJP(1Z0-851) 模拟题分析(六)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  3. Metrics介绍

    Metrics可以为你的代码的运行提供无与伦比的洞察力.作为一款监控指标的度量类库,它提供了很多模块可以为第三方库或者应用提供辅助统计信息, 比如Jetty, Logback, Log4j, Apac ...

  4. [SVN] SVN在Eclipse里的各个状态解释

    中文意义: A代表添加D代表删除U代表更新C代表合并,并且合并中有冲突G代表合并,合并中没有冲突 每个字母代表的意义: U = item (U)pdated to repository version ...

  5. vim用法小节

    1.把一个文件的内容全选复制到另一个文件 方案一: gg"*yG 然后另外一个vim "*p "*是系统剪贴板寄存器 方案二: 打开另一个文件,然后输入 :r filen ...

  6. Android学习系列(37)--App调试内存泄露之Context篇(下)

    接着<Android学习系列(36)--App调试内存泄露之Context篇(上)>继续分析. 5. AsyncTask对象 我N年前去盛大面过一次试,当时面试官极力推荐我使用AsyncT ...

  7. java&Protocol Buffers

    ps: Protocol Buffers简称PB PB 安装配置 下载 PB: 在 PB 官网,下载最新版(或者其他版本)PB,这里为了与 Java 项目中的 PB Maven 依赖版本一致,使用 P ...

  8. POJ 3261 后缀数组

    题目链接:http://poj.org/problem?id=3261 题意:约翰注意到奶牛产奶的之类是不断变化的,虽然他不能预测从当天到下一天的变化情况但是他知道变化是有规律的,牛奶的质量由一个整数 ...

  9. shell-bash学习01基础、打印、环境变量

    基础 终端提示符: username@hostname$; $: 一般用户 #:root用户 运行脚本 Bash执行: * bash script.sh; 直接运行: 脚本开头添加shebang起始: ...

  10. AutoMapper简明教程(学习笔记)

    ].FirstName + nameDto12[].LastName);Console.WriteLine();//Console.ReadKey();//emitMapper error//List ...