题目链接

输出路径,搞了一个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. 初识SQL Server Integration Service

    SSIS(SQL Server Integration Service)是Microsoft 从SQL Server2005 以后发布的,现在一直跟随每个SQL server版本.它是Microsof ...

  2. 登录成功,拿到token

    历尽波折,终于成功登录并拿到了token: - (LoginResultDto *)login:(NSString *)userName andPassword:(NSString *)passwor ...

  3. PHP二维数组的分页

    方法一: <?php $arr_click = array( array( 'clicks' => 3, 'clickDate' =>'2015-10-11' ), array( ' ...

  4. android:imeOptions属性(转)

    默认情况下软键盘右下角的按钮为“下一个”,点击会到下一个输入框,保持软键盘 设置 android:imeOptions="actionDone" ,软键盘下方变成“完成”,点击后光 ...

  5. UVA 11987 Almost Union-Find (并查集+删边)

    开始给你n个集合,m种操作,初始集合:{1}, {2}, {3}, … , {n} 操作有三种: 1 xx1 yy1 : 合并xx1与yy1两个集合 2 xx1 yy1 :将xx1元素分离出来合到yy ...

  6. hdu 2669 Romantic

    Romantic Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  7. 利用scp传输文件小结

    从本地复制到远程 scp mysql-5.5.29-linux2.6-x86_64.tar.gz 192.168.1.11:/opt 指定端口: scp -P 60022 /opt/ray/nginx ...

  8. HTML DOM学习之一

    1.HTML DOM定义了访问和操作HTML文档的标准方法:DOM以树型结构表达了HTML文档: 2.DOM是W3C的标准,定义了访问HTML和XML文档的标准: DOM(文档对象模型)是中立于平台和 ...

  9. ubuntu 下python版本切换

    1. 安装ubuuntu 14.04之后python的默认版本为2.7.6但是我想使用python的版本为3.4 可以打开终端:输入:alias python = python3

  10. 解决Kali Linux没有声音

    解决Kali Linux没有声音   Kali Linux系统默认状态下,root用户是无法使用声卡的,也就没有声音.启用的方法如下: (1)在终端执行命令:systemctl --user enab ...