偏方记录背包里的物品。。。。。每个背包的价值+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. NOIP2015斗地主[DFS 贪心]

    题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4< ...

  2. on事件委托

    on绑定多个事件,off解绑事件,one事件只执行一次 on除了能够处理未来事件,还可以对事件进行委托处理 $('div').on('click', 'p', function(event)(也就是通 ...

  3. EasyUI实现工地领款单项目

    环境搭建 引入jar.配置Spring MVC.web.xml.日志等 建表 自动生成MyBatis相关文件 mybatis-generator-core-1.3.2.jar <?xml ver ...

  4. ssh远程执行目标机器上的命令

    一句话: ssh -t -p 端口号 用户名@远程机器IP '远程机器上的命令完整路径' 例如: ssh -t -p 22 yangjunming@dev '/opt/app/deploy.sh' 注 ...

  5. 为什么 Java 8 中不再需要 StringBuilder 拼接字符串

    为什么 Java 8 中不再需要 StringBuilder 拼接字符串 来源:codeceo 发布时间:2016-12-27 阅读次数:427 0   在Java开发者中,字符串的拼接占用资源高往往 ...

  6. 【翻译】DotNetMQ: 一个.NET版完整的消息队列系统

    在一个大型的分布式系统中,消息队列是不可缺少的中间件,能很好的解决异步消息.应用解耦.均衡并发等问题.在.net中,偶然发现一个效率不错.安全可靠.功能齐全的消息组件,忍不住翻译过来,供大家快速预览. ...

  7. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

  8. Win10激活KMS

    Windows 10是目前微软主推的Windows系统,Win10 相对之前的Win7/8是吸取二者之长,发展而来! 目前新装的Windows10默认没有激活的 芝麻开们:http://pan.bai ...

  9. APP

    第一天 1.环境初步搭建 SmartSniff fiddler ddms AntiDroid Android Killer 百度方法 http://jingyan.baidu.com/article/ ...

  10. mysql中价格用什么数据类型表示最佳?

    DECIMAL和NUMERIC都行DECIMAL和NUMERIC类型在MySQL中视为相同的类型.它们用于保存必须为确切精度的值,例如货币数据.当声明该类型的列时,可以(并且通常要)指定精度和标度:例 ...