Happy Programming Contest  ZOJ3703

老实说:题目意思没看懂。。。(希望路过的大神指点)

最后那个the total penalty time是什么意思啊!!!

还是学到点东西的。。。

解题的关键在于:要控制最后所用的时间最少,所以在程序的最开始应该先将输入的各种题目 以时间升序排列, 然后就可以保证每次都以时间小的优先选, 这样就可以保证最后相同的吸引值和解题数的情况下所花的时间最少。

 #include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Point
{
int t,v;
}p[];
bool cmp(Point left,Point right)
{
return left.t<right.t;
}
int dp[],pen[],pro[];
int main ()
{
int test;scanf("%d",&test);
while(test--)
{
int len,n;
scanf("%d%d",&len,&n);
memset(dp,,sizeof(dp));
memset(pro,,sizeof(pro));
memset(pen,,sizeof(pen));
for(int i=;i<=n;++i)
scanf("%d",&p[i].t);
for(int i=;i<=n;++i)
scanf("%d",&p[i].v);
int ans_val=,ans_p=,penalty=;
sort(p+,p++n,cmp);
for(int i=;i<=n;++i)
{
for(int j=len;j>=p[i].t;--j)
{
bool flag=false;
if(dp[j-p[i].t]+p[i].v>dp[j])
flag=true;
else if(dp[j-p[i].t]+p[i].v==dp[j] && pro[j-p[i].t]+>pro[j])
flag=true;
else if(dp[j-p[i].t]+p[i].v==dp[j] && pro[j-p[i].t]+==pro[j] && pen[j-p[i].t]+j<pen[j])
flag=true;
if(flag)
{
dp[j]=dp[j-p[i].t]+p[i].v;
pro[j]=pro[j-p[i].t]+;
pen[j]=pen[j-p[i].t]+j; }
}
}
for(int j=;j<=len;++j)
{
bool flag=false;
if(ans_val<dp[j])
flag=true;
else if(ans_val==dp[j] && ans_p<pro[j])
flag=true;
else if(ans_val==dp[j] && ans_p<pro[j] && penalty>pen[j])
flag=true;
if(flag)
{
ans_val=dp[j];
ans_p=pro[j];
penalty=pen[j];
}
}
printf("%d %d %d\n",ans_val,ans_p,penalty);
}
return ;
}

Happy Programming Contest(ZOJ3703)(01背包+路径储存)的更多相关文章

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

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

  2. Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)

    A - Coins Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Descript ...

  3. UVA 624 ---CD 01背包路径输出

    DescriptionCD You have a long drive by car ahead. You have a tape recorder, but unfortunately your b ...

  4. Coderfroces 864 E. Fire(01背包+路径标记)

    E. Fire http://codeforces.com/problemset/problem/864/E Polycarp is in really serious trouble — his h ...

  5. UVA--624 CD(01背包+路径输出)

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

  6. HDOJ 5188 zhx and contest 贪婪+01背包

    zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. UVA 624 CD【01背包+路径记录】

    You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is o ...

  8. uva624 CD (01背包+路径的输出)

    CD Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 624 ...

  9. HDU 6083 度度熊的午饭时光(01背包+记录路径)

    http://acm.hdu.edu.cn/showproblem.php?pid=6083 题意: 思路: 01背包+路径记录. 题目有点坑,我一开始逆序枚举菜品,然后一直WA,可能这样的话路径记录 ...

随机推荐

  1. Access批量操作

    鉴于C#要插5万条记录到Access很慢,在网上找了好久的资料,终于找到了比较有用的信息(转载自Bach)谢谢! 总结如下: 1.导出TXT:  select * into [data.txt] in ...

  2. $anchorScroll和$cache

    1.$achorScroll服务---用于描点跳转 $scope.change = function(id){ $location.hash(id); $anchorScroll(); }; 只要给l ...

  3. Javascript.ReactNative-2-javascript-syntax-in-react-native

    JavaScript Syntax in React Native Contents: Arrow Function Let+Const Default + Rest + Spread Destruc ...

  4. android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别

    android Activity类中的finish().onDestory()和System.exit(0) 三者的区别 Activity.finish() Call this when your a ...

  5. Co-saliency-Huazhu Fu

    这里主要是fu老师的显著性检测分割的一些资料. 对应的主页为:http://hzfu.github.io/ 对应的一些codes:https://github.com/HzFu

  6. 浅谈SDN和NFV之间的关系

    一个行业固定设备的折旧周期很长,任何变革的发生都绝非易事,但是网络却一次性面临两项革新--软件定义网络(SDN)和网络功能虚拟化(NFV),在变革网络的过程中,二者若想取得成功可能会依赖彼此的技术,或 ...

  7. tomcat监控

    参考:http://www.linuxidc.com/Linux/2012-11/74003.htm #!/bin/sh monitorlog=/opt/tomcat7/logs/monitor.lo ...

  8. Java 获取 Unix时间戳

    unix时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒. 在大多数的UNIX系统中UNIX时间戳存储为32位,这样会引发2038年问题. 但是,因为需求是需要int类 ...

  9. Android学习 之 ColorStateList按钮文字变色

    首先添加一个ColorStateList资源XML文件,XML文件保存在res/color/button_text.xml: <?xml version="1.0" enco ...

  10. jQuery基础_3

    DOM:文档处理内部插入:父子级关系$("a").append($("b"))把b插入到a中[a里面的后面]$("b").appendTo( ...