2697: 特技飛行

來源:互聯網
上載者:User

標籤:

2697: 特技飛行Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 646  Solved: 393
[Submit][Status]Description

神犇航空開展了一項載客特技飛行業務。每次飛行長N個單位時間,每個單位時間可以進行一項特技動作,可選的動作有K種,每種動作有一個刺激程度Ci。如果連續進行相同的動作,乘客會感到厭倦,所以定義某次動作的價值為(距上次該動作的時間)*Ci,若為第一次進行該動作,價值為0。安排一種方案,使得總價值最大。

Input  第一行,兩個數,N和K,如上所述;
  第二行,K個正整數,表示K種動作的Ci值。
Output  僅一行,一個整數,表示最大總價值。
Sample Input5 2
2 2

Sample Output12

HINT

資料規模及約定

  對於10%的測試資料,N<=20,K<=3

  對於全部的測試資料,1<=N<=1000,1<=K<=300,0<=Ci<=1000。

Source

 

題解:這個嘛,是個萌萌噠貪心啦啦啦——先從大到小排序,然後依次往兩邊擺上 ,不難證明其最優性

 1 var
 2    i,j,k,m,n,ll,l,r,x,y:longint;
 3    a:array[0..2000] of longint;
 4 procedure swap(var x,y:longint);inline;
 5           var z:longint;
 6           begin
 7                z:=x;x:=y;y:=z;
 8           end;
 9 procedure sort(l,r:longint);
10           var i,j,x,y:longint;
11           begin
12                i:=l;j:=r;x:=a[(l+r) div 2];
13                repeat
14                      while a[i]>x do inc(i);
15                      while a[j]<x do dec(j);
16                      if i<=j then
17                         begin
18                              swap(a[i],a[j]);
19                              inc(i);dec(j);
20                         end;
21                until i>j;
22                if i<r then sort(i,r);
23                if l<j then sort(l,j);
24           end;
25 begin
26      readln(n,m);
27      for i:=1 to m do read(a[i]);
28      readln;
29      sort(1,m);
30      x:=1;y:=n;
31      for i:=1 to m do
32          begin
33               ll:=ll+(y-x)*a[i];
34               inc(x);dec(y);
35               if x>=y then break;
36          end;
37      writeln(ll);
38      readln;

39 end.          

2697: 特技飛行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.