Problem:the World Final II (NEUOJ1175) sort + dynamic Planning

Source: Internet
Author: User
Tags time 0

The World Final is coming! Next Week our seniors, Brother Head, Little Bin and God Tan would fight for the glory of NEU.

The rule of the world Final is as follow:

1. If the teams has the different solved problems, then the one who has more solved problems would get higher rank;

2. If the teams has the same solved problems, then the one who has less penalty, which equals 0 initially, would get high ER rank;

3. If one team get first AC of a problem, then their penalty would add a number which equal the time they first AC it, and If they tried failed k times to solve it before they AC it, then they would get more k*20 penalty;

4. The total time of the world final was including, and begin at time 0.

Now we seniors know how long would they solve each problem and how many times would they failed before they AC it. They wanna take a best strategy to get higher rank.

Input
There is T groups of test data. The first line contains one positive integer T (1<=t<=100).

For each test data:the first line contains a integer n (1<=n<=15), which is the number of total problems. Then follows N line, each line contains the Numbers:ti and Ki, (1<=ti<=300, 0<=ki<=1000) which means how long Would they AC it (not the time they AC it), and how many times they failed before they ac it.

"Hint":

In the second sample input, they solve the 2nd problem Firstly, then solve the 1st problem, solve they solved 2 problems i n Total, and penalty= (2+100*20) + (292+2*20) =2334.

Output
For each case, the output one line contains the numbers separated by a space:the the most number of problems they can solve, and The less penalty.


Sample Input
2 2 290 2 299 1 3 290 2 2 100 299 1
Sample Output
1 319 2 2334
Source
Morejarphone
Hint
No hint!
Submit
The specific topic is this, there are a total of n problems, each problem has a specific time and a fixed number of failures (this incredibly can also know!!) ), the rules of ACM students should be very clear ~ 300 minutes of competition, each to make a topic AC number plus one, the time to increase the amount of time for the current number of times, each failure to increase the penalty for 20 minutes. (for example, in an hour to do a problem, the time added (60+20* failure)) finally to see the total number of titles to rank, over the same number of times the same time, the less the place the more forward. The final requirement is to output the best case in a specified time (i.e., the number of problems (maximum) and the time spent (minimum)).

I used the method is 01 backpack DP solution, the backpack capacity is 300 minutes, for a problem, the update condition is can increase the number of problems or the number of problems, but the time is reduced. Here is another problem, in the use of the backpack before the data order, because if the final passage of the topic fixed, then want to make the least time, it is necessary to put fewer times in front of the problem, because the number of failures *20 is fixed penalty, and the problem time is not related. So for the two different times of the topic, we must first do a little time to ensure that the shortest possible (the part of the writing sort is weaker, the sort is secretly sorted ...). But to reload the less than, this should be BA. , you can also use the sort function and then add a third parameter in the sort to execute) and then iterate over the array to find the maximum number of problems (priority), and the minimum usage time, the last output is good ~

AC Code:

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace Std;

Class Ti
{
Public
int ft,ts;
BOOL operator < (const TI &b) const//overloaded operator
{
if (ft<b.ft)
return true;
Else
return false;
}
};

TI dp[50];


int main ()
{
int t;
scanf ("%d", &t);
while (t--)
{
int n;
int num[310]={0},time[310]={0};
int x=0,y=0x3f3f3f3f;//0x3f3f3f3f Approximate maximum value
scanf ("%d", &n);
for (int i=1;i<=n;i++)
scanf ("%d%d", &dp[i].ft,&dp[i].ts);
Sort (dp+1,dp+n+1);//take care not to sort DP "0"
for (int i=1;i<=n;i++)
for (int j=300;j>=dp[i].ft;j--)
{
if (time[j]==0)
{
num[j]++;
Time[j]=dp[i].ft+20*dp[i].ts;
}
else if (num[j]-num[j-dp[i].ft]==1)//The number of parts is constant but the time is reduced
{
if (TIME[J]&GT;TIME[J-DP[I].FT]+20*DP[I].TS+J)
{
num[j]=num[j-dp[i].ft]+1;
Time[j]=time[j-dp[i].ft]+20*dp[i].ts+j;
}
}
else if (num[j]-num[j-dp[i].ft]==0)//can increase the number of instances of the problem
{
num[j]=num[j-dp[i].ft]+1;
Time[j]=time[j-dp[i].ft]+20*dp[i].ts+j;
}
printf ("%d:num%d=%d time%d=%d\n", I,j,num[j],j,time[j]);
if (num[j]==x)////This paragraph of judgment should pay attention to the first to judge the change of the number of problems, the number of problems, the minimum time not to change, WA once ....
Y=min (Y,time[j]);
else if (num[j]>x)
{
X=NUM[J];
Y=TIME[J];
}
}
printf ("%d%d\n", x, y);
}
return 0;
}

Problem:the World Final II (NEUOJ1175) sort + dynamic Planning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.