偏方记录背包里的物品。。。。。每个背包的价值+0.01

Happy Programming Contest


Time Limit: 2 Seconds      Memory Limit: 65536 KB

In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Since the girl would prefer pink balloon rather than black balloon, each color is assigned a value to measure its attractiveness. Usually, the boy is good at programming while the girl is charming. The boy wishes to solve problems as many as possible. However, the girl cares more about the lovely balloons. Of course, the boy's primary goal is to make the girl happy rather than win a prize in the contest.

Suppose for each problem, the boy already knows how much time he needs to solve it. Please help him make a plan to solve these problems in strategic order so that he can maximize the total attractiveness value of balloons they get before the contest ends. Under this condition, he wants to solve problems as many as possible. If there are many ways to achieve this goal, he needs to minimize the total penalty time. The penalty time of a problem is equal to the submission time of the correct solution. We assume that the boy is so clever that he always submit the correct solution.

Input

The first line of input is an integer N (N < 50) indicating the number of test cases. For each case, first there is a line containing 2 integers T (T <= 1000) and n (n <= 50) indicating the contest length and the number of problems. The next line contains n integers and the i-th integer ti (ti <= 1000) represents the time needed to solve the ith problem. Finally, there is another line containing n integers and the i-th integer vi (vi <= 1000) represents the attractiveness value of the i-th problem. Time is measured in minutes.

Output

For each case, output a single line containing 3 integers in this order: the total attractiveness value, the number of problems solved, the total penalty time. The 3 integers should be separated by a space.

Sample Input

2
300 10
10 10 10 10 10 10 10 10 10 10
1 2 3 4 5 6 7 8 9 10
300 10
301 301 301 301 301 301 301 301 301 301
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output

55 10 550
0 0 0


Author: HUANG, Qiao
Contest: The 13th Zhejiang University Programming Contest

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; struct timu
{
int w;
double v;
}TM[]; double bag[];
int G[][],V,N,t; bool cmp(timu a,timu b)
{
return a.w<b.w;
} int main()
{
cin>>t;
while(t--)
{
memset(bag,,sizeof(bag));
memset(G,,sizeof(G)); cin>>V>>N;
for(int i=;i<=N;i++) cin>>TM[i].w;
for(int i=;i<=N;i++) cin>>TM[i].v,TM[i].v+=0.01;
sort(TM+,TM++N,cmp);
for(int i=;i<=N;i++)
{
for(int j=V;j>=TM[i].w;j--)
{
if(bag[j]<=bag[j-TM[i].w]+TM[i].v)
{
G[i][j]=;
bag[j]=bag[j-TM[i].w]+TM[i].v;
}
}
}
vector<int> vv;
int valu=V;
for(int i=N;i>=;i--)
{
if(G[i][valu])
{
valu-=TM[i].w;
vv.push_back(TM[i].w);
}
}
int nth=vv.size();
int arr[],time=,tmp=;
for(int i=;i<nth;i++) arr[i]=vv[i];
sort(arr,arr+nth);
for(int i=;i<nth;i++)
{
tmp+=arr[i];
time+=tmp;
}
cout<<(int)bag[V]<<" "<<nth<<" "<<time<<endl;
} return ;
}

ZOJ 3703 Happy Programming Contest的更多相关文章

  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(DP)

    题目链接 输出路径,搞了一个DFS出来,主要是这里,浪费了好长时间. #include <cstdio> #include <string> #include <cstr ...

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

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

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

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

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

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

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

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday

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

  9. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients

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

随机推荐

  1. 关于JS的编码转换问题

    在进行JS开发过程中,尤其是在开发报表时,报表已集成到Web页面中,通过在页面传递参数至报表中时,会发现有时某些参数值,传递到报表中是显示为问号或乱码等等一系列不能正常显示的情况. 这是由于浏览器和报 ...

  2. ECharts 初体验

    缘起 ECharts,缩写来自Enterprise Charts,商业级数据图表,它最初是为了满足公司商业体系里各种业务系统(如凤巢.广告管家等等)的报表需求.以前这些系统的图表需求我们都是使用fla ...

  3. AC日记——I Hate It 洛谷 P1531

    题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...

  4. thinkphp发送邮件

    看thinkPHP手册发送邮件 Thinkphp3.2 PHPMailer 发送邮件结合QQ企业邮箱发送邮件下载附件PHPMailer解压到ThinkPHP\Library\VendorPHPMail ...

  5. 【swift学习笔记】三.使用xib自定义UITableViewCell

    使用xib自定义tableviewCell看一下效果图 1.自定义列 新建一个xib文件 carTblCell,拖放一个UITableViewCell,再拖放一个图片和一个文本框到tableviewc ...

  6. 回文自动机(BZOJ2565)

    #include <cstdio> #include <cstring> #include <iostream> using namespace std; ][], ...

  7. 【抓包工具】wireshark

    wireshark下载地址:http://download.csdn.net/detail/victoria_vicky/8819777 一.wireshark优劣势 wireshark劣势:只能查看 ...

  8. SharePoint中使用C#跳转页面的研究

    最近开发SharePoint的时候遇到问题,不能完成跳转,于是归纳了一下方法(最后还是使用了js跳转,后台跳转被sharepoint限制了). 1.最常用的页面跳转(原窗口被替代):Response. ...

  9. 教你一招:解决Win10 win7 删除文件或文件夹时提示“找不到该项目”

    问题很怪异,解决的办法却很简单. 首先,分析问题 使用不可显示ASCII字符或采用UNICODE字符方法创建的文件或文件夹: 名称中含有..等特殊符号文件或文件夹名称不符合Windows命名规范或建立 ...

  10. onmousewheel跟onscroll的区别

    研习DOM中的事件方法,发现一些细微差别,百度一下没有类似的解答,随手记下来. onmousewheel事件  以下摘自http://help.dottoro.com/ljmracjb.php Bro ...