题目链接

输出路径,搞了一个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. 【openGL】画五角星

    #include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...

  2. 单链表带头结点&不带头结点

    转自:http://blog.csdn.net/xlf13872135090/article/details/8857632 Node *head;  //声明头结点   带头结点初始化 void I ...

  3. PAT A 1013. Battle Over Cities (25)【并查集】

    https://www.patest.cn/contests/pat-a-practise/1013 思路:并查集合并 #include<set> #include<map> ...

  4. V for Vendetta

    V for Vendetta V字仇杀队 复仇者V 安迪·沃卓斯基 and Larry Wachowski 思想,是最强大的武器.因为,世界上的独裁政府,有一个共同特点就是推行洗脑和愚民政策. 经典台 ...

  5. LeetCode——Reverse Integer(逆置一个整数)

    问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321   Ha ...

  6. 深入解析结构化异常处理(SEH)

    jpg 改 rar

  7. Linux学习笔记(14)文件系统管理

    1 回顾分区与系统 (1)分区类型 Linux的分区一般包括主分区,扩展分区和逻辑分区.其中: 主分区最多只能分4个: 扩展分区只能有一个,也算作主分区的一种,即主分区加扩展分区最多有4个.但扩展分区 ...

  8. Struts2基本配置详解

    Struts2配置文件加载顺序 struts2 配置文件由核心控制器加载 StrutsPrepareAndExecuteFilter (预处理,执行过滤) init_DefaultProperties ...

  9. poj 1141 区间dp+递归打印路径

    Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30383   Accepted: 871 ...

  10. ASP.Net MVC开发基础学习笔记(5):区域、模板页与WebAPI初步

    一.区域—麻雀虽小,五脏俱全的迷你MVC项目 1.1 Area的兴起 为了方便大规模网站中的管理大量文件,在ASP.NET MVC 2.0版本中引入了一个新概念—区域(Area). 在项目上右击创建新 ...