[I will also give a brief description of the problem] Software Company

Source: Internet
Author: User

[Description]

N people, two projects, each having M same parts. The minimum time required for each person to complete a certain project is different.

[Input format]

Row 1: Number N and part M.

Next n rows, two numbers per line: the time required for I to complete one part of the two projects.

[Output format]

One row: the fastest time.

[Example input]

3 20

1 1

2 4

1 6

[Sample output]

18

[Data Scope]

1 <= n, m <= 100.

[Analysis]

The total time used by the binary enumeration, and then the dynamic plan is used to determine whether the result can be completed. Similar to the question "Green Channel" issued by students in Tangshan No. 1 school. But it is simpler than that.

Dynamic Identification:

The current time to be determined is mid. f [I] [J] is used to represent the previous I, and the first project of J is completed. The second project can complete up to several copies. The state transition equation is f [I] [J] = max (F [I-1] [J-K] + (mid-K * W [I] [0]). /W [I] [1]). Finally, determine whether f [N] [m] is greater than M.

// Problem: software company // By Sephiroth Lee/Date: 10/9/2010 # include <stdio. h> # include <string. h ># include <iostream> # define maxn 110 using namespace STD; int W [maxn] [2], F [maxn] [maxn]; int n, m, max_time, l, R, mid; bool check (INT mid) {memset (F,-1, sizeof (f); F [0] [0] = 0; for (INT I = 1; I <= N; ++ I) for (Int J = 0; j <= m; ++ J) {If (F [I-1] [J] <0) continue; For (int K = 0; (j + k <= m) & (mid> = W [I] [0] * k); ++ K) if (F [I] [J + k] <F [I-1] [J] + (mid-W [I] [0] * K) /W [I] [1]) f [I] [J + k] = f [I-1] [J] + (mid-W [I] [0] * K) /W [I] [1];} return f [N] [m]> = m;} int main () {freopen ("software. in "," r ", stdin); freopen (" software. out "," W ", stdout); scanf (" % d ", & N, & M); For (INT I = 1; I <= N; ++ I) {scanf ("% d", & W [I] [0], & W [I] [1]); if (W [I] [0]> max_time) max_time = W [I] [0]; If (W [I] [1]> max_time) max_time = W [I] [1];} r = max_time * m; L = 1; while (L <= r) {mid = (L + r)/2; if (check (MID) r = mid-1; else l = Mid + 1;} printf ("% d \ n", L); Return 0 ;}

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.