Two-point + dynamic planning POJ 1973 software company

Source: Internet
Author: User

Software company
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 1112 Accepted: 482

Description

A software Developing company has been assigned, programming projects. As both projects is within the same contract, both must be handed on at the same time. It does is finished earlier.

This company had n employees to do the jobs. To manage the and the projects more easily, which are divided into M independent subprojects. Only one employee can work in a single subproject at one time, but it's possible for the employees to work on different s Ubprojects of the same project simultaneously.

Our goal are to finish the projects as soon as possible.

Input

The first line of the input file contains a single integer t (1 <= T <= one), the number of test cases, followed by t He input data for each test case. The first line of all test case contains, integers n (1 <= n <=), and M (1 <= m <= 100). The input for this test case would be a followed by n lines. Each line contains-integers which specify how much time in seconds it'll take for the specified employee to complete One subproject of each project. So if the line contains x and Y, it means it takes the employee X seconds to complete a subproject from the first pro Ject, and Y seconds to complete a subproject from the second project.

Output

There should be one line per test case containing the minimum amount of time in seconds after which both projects can be C ompleted.

Sample Input

13 201 12) 41 6

Sample Output

18
1 /*since the dynamic programming equation to transfer too much, then we will take the time as a binary object, the time of the two points, assuming a minimum time (everyone can not exceed the time), to carry out the dp,f[i][j] is the former I do J a project can do the largest number of B projects, 2 equation: d[i][j] = max {d[i][j], D[i][j-k] + (time-a[i] * k)/b[i]}3 Enumerate the person I do k a project, the remaining time to do B project, just check d[i][m] "=m is able to this time. 4 Of course we can also use a scrolling array to compress space. */5 #defineN 1016#include <iostream>7 using namespacestd;8#include <cstdio>9#include <cstring>Ten structqu{ One     intN,m,a[n],b[n],f[n]; A     voidInitintXinty) -     { -n=x;m=y; thememset (A,0,sizeof(A)); -memset (B,0,sizeof(B)); -Memset (F,0,sizeof(f)); -     } +     voidAddintAintBinti) -     { +A[i]=a; b[i]=b; A     } at     BOOLCheckintV) -     { -memset (f,-1,sizeof(f)); -          for(intI=0; i<=m;++i) -{/*Initialize the first person to do I a project case*/ -             if(i*a[1]&GT;V) Break; inF[i]=max (F[i], (v-i*a[1])/b[1]); -         } to         if(f[m]>=m)return true; +          for(intI=2; i<=n;++i) -         { the              for(intj=m;j>=0;--j) *{/*enumeration before i-1 how many a*/ $                  for(intk=0; k<=j;++k)Panax Notoginseng{/*enumeration I personally made K a project*/ -                     if(V<k*a[i]) Break; the                     if(f[j-k]!=-1) +F[j]=max (f[j],f[j-k]+ (v-k*a[i])/b[i]); A                 /*Note Before-1 people may not be able to do j-k items, this time if the transfer, that is the former I-1 personal total spent-1 times, apparently not test instructions*/ the                                 } +             } -             if(f[m]>=m)return true; $         } $         return false; -     } - }q; the intMain () - {Wuyi     inttes; thescanf"%d",&tes); -     intn,m; Wu      while(tes--) -     { Aboutscanf"%d%d",&n,&m); $ Q.init (n,m); -         intb; -         intmaxx=-1; -          for(intI=1; i<=n;++i) A         { +scanf"%d%d",&a,&b); the Q.add (a,b,i); -maxx=Max (Maxx,max (A, b)); $         } the         intL=0, r=maxx*m*2; the         intmid; the          while(l<=R) the         { -Mid= (l+r) >>1; in             if(Q.check (mid)) ther=mid-1; the             ElseL=mid+1; About         } theprintf"%d\n", L); the          the     } +     return 0; -}

Two-point + dynamic planning POJ 1973 software company

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.