usaco 3.4 Raucous Rockers 2010.8.4

来源:互联网 发布:淘宝客阿里云建站教程 编辑:程序博客网 时间:2024/04/30 20:25

Raucous Rockers

You just inherited the rights to N (1 <=N <= 20) previously unreleased songs recorded by the popular group RaucousRockers. You plan to release a set of M (1 <= M <= 20) compact disks witha selection of these songs. Each disk can hold a maximum of T (1 <= T <=20) minutes of music, and a song can not overlap from one disk to another.

 

Since you are a classical music fan andhave no way to judge the artistic merits of these songs, you decide on thefollowing criteria for making the selection:

 

The songs on the set of disks must appearin the order of the dates that they were written.

The total number of songs included will bemaximized.

PROGRAM NAME: rockers

INPUT FORMAT

Line 1: Three integers: N, T, and M.

Line 2: N integers that are the lengths ofthe songs ordered by the date they were written.

 

 

SAMPLE INPUT (file rockers.in)

4 5 2

4 3 4 2

OUTPUT FORMAT

A single line with an integer that is thenumber of songs that will fit on M disks.

 

SAMPLE OUTPUT (file rockers.out)

3


/*ID:PROG:rockersLANG:C++*/#include <cstdio>#include <cstring>#define MAXN 25int max[MAXN],g[MAXN][MAXN],t[MAXN];int main(){int n,T,m;freopen("rockers.in","r",stdin);freopen("rockers.out","w",stdout);scanf("%d %d %d",&n,&T,&m);for(int i=1;i<=n;i++)   scanf("%d",&t[i]);for(int i=1;i<=n;i++)   for(int j=m;j>=1;j--)   {    g[j][0]=max[j-1];    for(int v=T;v>=t[i];v--)    {     if (g[j][v]<=g[j][v-t[i]]+1)      g[j][v]=g[j][v-t[i]]+1;     if (g[j][v]>max[j])      max[j]=g[j][v];    }   }printf("%d\n",max[m]);return 0;}


Compiling...

Compile: OK

 

Executing...

  Test 1: TEST OK [0.011 secs, 2884 KB]

  Test 2: TEST OK [0.000 secs, 2884 KB]

  Test 3: TEST OK [0.000 secs, 2884 KB]

  Test 4: TEST OK [0.000 secs, 2884 KB]

  Test 5: TEST OK [0.000 secs, 2884 KB]

  Test 6: TEST OK [0.000 secs, 2884 KB]

  Test 7: TEST OK [0.022 secs, 2884 KB]

  Test 8: TEST OK [0.000 secs, 2884 KB]

  Test 9: TEST OK [0.000 secs, 2884 KB]

  Test 10: TEST OK [0.011 secs, 2884 KB]

  Test 11: TEST OK [0.011 secs, 2884 KB]

  Test 12: TEST OK [0.000 secs, 2884 KB]

 

All tests OK.

 

YOUR PROGRAM ('rockers') WORKED FIRST TIME!That's fantastic

-- and a rare thing. Please accept thesespecial automated

congratulations.

 

Here are the test data inputs:

 

------- test 1 -------

4 5 2

4 2 4 3

------- test 2 -------

1 1 5

6

------- test 3 -------

10 5 5

5 3 5 3 5 3 5 3 5 2

------- test 4 -------

10 10 9

9 7 8 6 10 9 8 6 5 9

------- test 5 -------

9 15 4

15 7 8 6 9 5 10 4 11

------- test 6 -------

15 10 1

3 6 7 9 6 8 6 7 5 8 10 7 6 3 4

------- test 7 -------

20 20 2

10 15 19 18 11 15 14 16 12 14 15 10 10 1614 16 14 15 16 10

------- test 8 -------

20 20 10

18 15 16 10 2 20 14 17 3 7 16 15 18 16 2016 13 9 4 16

------- test 9 -------

18 10 6

4 9 6 3 9 7 6 9 4 1 10 9 5 8 5 4 7 6

------- test 10 -------

10 10 20

8 3 6 4 10 8 2 9 5 10

------- test 11 -------

20 20 5

4 9 2 19 5 3 10 15 18 4 3 9 14 17 1 20 1519 12 6

------- test 12 -------

20 20 10

19 15 1 5 6 19 15 18 13 19 18 5 3 6 2 6 1913 15 16

Keep up the good work!

 

 

Thanks for your submission!

 


0 0
原创粉丝点击