ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品。。。。。每个背包的价值+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
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的更多相关文章
- ZOJ 3703 Happy Programming Contest(0-1背包)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...
- ZOJ 3703 Happy Programming Contest(DP)
题目链接 输出路径,搞了一个DFS出来,主要是这里,浪费了好长时间. #include <cstdio> #include <string> #include <cstr ...
- 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 在 KVM 上安装 Win7 虚拟机
之前都是在用Linux 虚机,现在有需要用到Win7 虚机,才发现在 KVM 上安装 Win7 的过程远比想象中的复杂.本文就把其过程做个简单总结. 1. 在 Virtual Machine Mana ...
- 数-模(D/A)转换器
将实现数字信号到模拟信号的转换电流称为数模(D/A)转换器,简称为DAC(Digital - Analog Convert). 目前常见的D/A转化器中,有:权电阻网络D/A转换器.倒T型电阻网络D/ ...
- sqlServer下展示某库中所有的表
- jquery的add()用法总结
<!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...
- MathType for mac 能够实现在Word里面双击公式编辑的方法
最近我遇到了一个问题,在使用Word编辑公式时遇到了阻碍. 问题: 我为了顺应潮流呢,用的是office for mac2016版本,在发现MathType安装好后,不能连接到Word里面,从Math ...
- redux middleware 的理解
前言 这几天看了redux middleware的运用与实现原理,写了一个百度搜索的demo,实现了类似redux-thunk和redux-logger中间件的功能. 项目地址:https://git ...
- js实现弹框及自动关闭
<SCRIPT LANGUAGE="javascript"> < !-- window.open (''page.html'',''newwindow'',''h ...
- 汇编语言标志位 含义 NV UP EI NG NZ AC PE CY
缩写原意: Overflow of = OV NV [No Overflow] Direction df = DN (decrement) UP (increment) Interrupt if = ...
- 2.0(3)MongoDB数据导入导出
——————(1)数据导出———————— 导出为JSON格式 mongoexport -d '数据库' -c '表名' -o ***.json 导出为csv mongoexport -d '数据库' ...
- Hibernate连接数据库超时设置autoReconnect=true
如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. 不用hibernate的话, connection url加参数: autoReconnect ...