【题目】

The ACM ICPC's rule of scoring is as the following:

A problem is solved when it is accepted by the judges. Teams are ranked according to the most problems solved. For the purposes of awards, or in determining qualifier(s) for the World Finals, teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved.

For example, if one has the following contest record:

  • At the 100th minute submitted problem A, rejected;
  • At the 140th minute submitted problem B, rejected;
  • At the 150th minute submitted problem B, accepted;
  • At the 160th minute submitted problem C, accepted.

Then his total time = (150+20) + 160 = 330. Notice that it took him only 10 minutes to finish problem C. Assume that he spent 40 minutes on reading all the problems through, then if he could do problem C first and problem A last, his contest record might look like:

  • At the 50th minute submitted problem C, accepted;
  • At the 90th minute submitted problem B, rejected;
  • At the 100th minute submitted problem B, accepted;
  • At the 160th minute submitted problem A, rejected.

Then his total time would be 50 + (100+20) = 170. Hence the order of solving the problems will affect one's final rank.

Now suppose that you are in a one-person team. It will take you t0t​0​​minutes to read all the problems through. Judging by your experience, you may estimate the minutes tit​i​​ that you will take to solve problem ii. And more, the earlier you get one problem done, the more unlikely that you will make mistakes on programming. Assume that if a solution is first time submitted in the first hour (60 minutes inclusive), it will get accepted at once; if it is first time submitted in the second hour, it will be rejected once; if it is first time submitted in the third hour, it will be rejected twice; etc. You may also estimate the minutes did​i​​ for debugging problem ii every time it is rejected. For the sake of simplicity, let us assume that did​i​​ is fixed for each problem ii, and once you start working on a problem, you will keep submitting until it is accepted.

Your task is to write a program to find yourself the order of solving the problems which gives you the best chance of winning the contest.

Input Specification:

Each input file contains several test cases. For each test case, the 1st line contains 3 integers: the total number of contest hours H (0 < H ≤ 5), the total number of problems N (0 < N ≤ 9), and the time t0t​0​​ (minutes) for you to read through all the problems at the beginning of the contest. The following N lines each contains a problem's name and a pair of positive integers tit​i​​ and did​i​​. A problem's name is a string of no more than 20 characters without any space. A negative H signals the end of input.

Output Specification:

For each test case, you are supposed to print to standard output the total time in a line in the format shown by the sample. Then print the names of the problems you will solve in the correct order, each name in a line. If there are several solutions, you must output the smallest sequence. A sequence of problems { i1i​1​​, i2i​2​​, ... ini​n​​ } is smaller than another sequence { j1j​1​​, j2j​2​​, ... jnj​n​​ } means that there exists an integer KK between 1 and nn such that for every 1kK1≤k<K, we have ikjki​k​​=j​k​​, and iKjKi​K​​<j​K​​.

【代码】

#include <iostream>
#include <string.h>
#define MAXP 10
using namespace std;int H=0,N,T0;
int T[MAXP],D[MAXP];//T:题目完成时间 D:题目debug时间
string problem_name[MAXP];
int fin_pro_No[MAXP];//按顺序记录完成的题目序号
bool pro_state[MAXP];//记录题目完成情况:true该题完成 false该题未完成
int final_num;
int final_pro_No[MAXP];
int final_totalTime;void update_strategy(int num, int totalTime){//控制策略的选择if (num < final_num) return;//优先选择做出题数多的策略if (num == final_num && totalTime>=final_totalTime) return;//做出题数一样,选择时间少的//更新策略final_num = num;final_totalTime = totalTime;for (int i=0; i<num; i++) {final_pro_No[i]=fin_pro_No[i];}
}//num:完成的题数
//usedTime:用掉的时间
//totalTime:成绩时间
void dfs(int num, int usedTime, int totalTime){int first_submit_time = usedTime + T[fin_pro_No[num]];int debug_times = (first_submit_time - 1)/60;int next_usedTime = first_submit_time + debug_times * D[fin_pro_No[num]];int next_totalTime = totalTime + next_usedTime + debug_times*20;if (next_usedTime <= H*60) {//规定时间内能成功提交本题num ++;if (num < N) {//还有未完成的题for (int i =0; i<N; i++) {//尝试每个可走的岔路if (!pro_state[i]) {pro_state[i]=true;fin_pro_No[num]=i;dfs(num, next_usedTime, next_totalTime);pro_state[i]=false;//===>剪枝//不用num--,num是形参,每层的num都不一样}}}else update_strategy(num, next_totalTime);//无题可做。找到一种策略,回到上一层===>}else update_strategy(num, totalTime);//超时。找到一种策略,回到上一层===>
}int main(){cin >> H;while (H>0) {cin >> N >> T0;for (int i=0; i<N; i++) {cin >> problem_name[i] >> T[i] >> D[i];}//变量初始化final_num = 0;final_totalTime = ~(1 << 31);memset(final_pro_No,0,sizeof(final_pro_No));memset(fin_pro_No, 0, sizeof(fin_pro_No));memset(pro_state, false, sizeof(pro_state));for (int i=0; i<N; i++) {pro_state[i]=true;fin_pro_No[0]=i;dfs(0, T0, 0);//用掉的时间为读题时间,成绩时间为0pro_state[i]=false;}cout << "Total Time = " << final_totalTime << endl;for (int i=0; i<final_num; i++) {cout << problem_name[final_pro_No[i]] << endl;}cin >> H;}return 0;
}

参考:http://blog.csdn.net/zccz14/article/details/51449748

ADS-WK11-Review of Programming Contest Rules-回溯剪枝相关推荐

  1. PTA Review of Programming Contest Rules

    题目重现 The ACM ICPC's rule of scoring is as the following: A problem is solved when it is accepted by ...

  2. 比赛题目训练系列17 (2020-2021 ACM-ICPC Brazil Subregional Programming Contest)

    比赛题目训练系列17 (2020-2021 ACM-ICPC Brazil Subregional Programming Contest) 训练网址 E. Party Company 给一棵树 (n ...

  3. 2016, IX Samara Regional Intercollegiate Programming Contest I. Deadline

    2016, IX Samara Regional Intercollegiate Programming Contest I. Deadline 题目看这里 Alex works as a devel ...

  4. Programming Contest Ranking(题解)

    Programming Contest Ranking . 题目描述 Heilongjiang Programming Contest will end successfully! And your ...

  5. freee Programming Contest 2022(AtCoder Beginner Contest 264)A~D题详细讲解

    目录 博主赛情 网站链接 比赛简介 Contest Information Reason why freee needs AtCoder users freee's business content ...

  6. 2015 HIAST Collegiate Programming Contest J

    Polygons Intersection 题意:给2个凸多边形,求相交面积 思路:不会,套板子就是了 AC代码: #include "iostream" #include &qu ...

  7. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  8. The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554

    地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others)     M ...

  9. 【AtCoder】diverta 2019 Programming Contest 2

    diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...

最新文章

  1. OpenCV运行ReID网络的实例(附完整代码)
  2. 进度条(页面刷新)【原创】
  3. 【CDH】 kafkaServer-gc.log日志太多
  4. ubuntu18.04下 c++安装opencv-3.4.6,c++安装opencv-3.4.9,clion配置opencv-3.4.6与 python安装 opencv-3.4.6
  5. js中事件捕获和事件冒泡
  6. 【EOS】2.1 EOS Hello World合约
  7. php正则 替换div标签内容,PHP 正则匹配标签内容,根据字符串长度进行替换
  8. ENVI入门系列教程---二、图像分析---9.遥感图像监督分类
  9. python 空对象,在Python中创建一个空对象
  10. 文档隐写溯源技术分析
  11. 微软输入法怎么最小化到托盘_Windows下的五笔输入法哪个最好用?我来推荐几款...
  12. c语言反三角函数有哪些,反三角函数公式有哪些?
  13. python中nx_python在nx在Python3中使用asyncio库进行快速数据抓取的教程
  14. Python爬取百度贴吧回帖中的微信号(基于简单http请求)
  15. 毛球科技论述区块链之符号理论(上)
  16. 3d max 场景转换对话框
  17. transformer模型的奥秘-学习笔记
  18. java服务端集成极光消息推送
  19. 原生态水平和垂直拉伸的JQUERY插件
  20. 浙江省中级工程师职称业绩要求

热门文章

  1. 分享Html模板5合一模板---50电影模板、56个游、86个体育项目、95个音乐网站、116个时尚
  2. 开放接口API(开发者的福利)
  3. html5通用兄第选择器,css 通用兄弟选择器( ~ )
  4. 数字图像处理课程实习——傅里叶变换与频域滤波
  5. 解决failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status co
  6. 一个新开端,存储服务器再添骨灰级玩家
  7. Edge 开发者日 · New Bing New Edge
  8. 特征可视化技术(CAM)
  9. mysql函数if为负数_MySQL的if,case语句
  10. 行为型:设计模式之访问者模式(二十三)