Pku1946 cow indexing ing

Source: Internet
Author: User

There are n cows running around the bicycle. If the cows need to run around X in one minute, the leader consumes x physical strength, and the latter consumes x physical strength. The number n of native cows is given now. The energy E of each native cow needs to be round D. As long as a cow reaches the D circle first, even if the loop is completed, the cow can complete the loop. If not, the output is 0. Otherwise, the shortest time of the output loop.

The optimal solution is obviously the nheaded cattle take turns to take the lead, and finally the nheaded bull line.

F [I, j, k] indicates that the I-lead has taken the J lap, and it has consumed the shortest time of K points of physical strength.

Write a forward equation f [I, j + X, K + x * x] = min {f [I, j, k] + 1} // leads the runner-up to continue running.

F [I + 1, J, J] = min {f [I, j, k]} // get started

View code

 1 program pku1946(input,output);
2 const
3 MAXW = 10000000;
4 var
5 f : array[0..25,0..110,0..110] of longint;
6 n,e,d : longint;
7 answer : longint;
8 procedure init;
9 begin
10 readln(n,e,d);
11 fillchar(f,sizeof(f),63);
12 end; { init }
13 function min(aa,bb :longint ):longint;
14 begin
15 if aa<bb then
16 exit(aa);
17 exit(bb);
18 end; { min }
19 procedure main;
20 var
21 i,j,k,l : longint;
22 begin
23 f[1,0,0]:=0;
24 for i:=1 to n do
25 for j:=0 to d do
26 for k:=0 to e do
27 if f[i,j,k]<19950714 then
28 for l:=1 to e do
29 begin
30 if (j+l<=d)and(k+l*l<=e) then
31 f[i,j+l,k+l*l]:=min(f[i,j,k]+1,f[i,j+l,k+l*l]);
32 f[i+1,j,j]:=min(f[i+1,j,j],f[i,j,k]);
33 end;
34 answer:=MAXW;
35 for i:=0 to e do
36 if f[n,d,i]<answer then
37 answer:=f[n,d,i];
38 end; { main }
39 procedure print;
40 begin
41 writeln(answer);
42 end; { print }
43 begin
44 init;
45 main;
46 print;
47 end.

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.