`
Simone_chou
  • 浏览: 185331 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

Watch The Movie(二维01背包)

    博客分类:
  • HDOJ
 
阅读更多

Watch The Movie

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 4558    Accepted Submission(s): 1438


Problem Description
New semester is coming, and DuoDuo has to go to school tomorrow. She decides to have fun tonight and will be very busy after tonight. She like watch cartoon very much. So she wants her uncle to buy some movies and watch with her tonight. Her grandfather gave them L minutes to watch the cartoon. After that they have to go to sleep.
DuoDuo list N piece of movies from 1 to N. All of them are her favorite, and she wants her uncle buy for her. She give a value Vi (Vi > 0) of the N piece of movies. The higher value a movie gets shows that DuoDuo likes it more. Each movie has a time Ti to play over. If a movie DuoDuo choice to watch she won’t stop until it goes to end.
But there is a strange problem, the shop just sell M piece of movies (not less or more then), It is difficult for her uncle to make the decision. How to select M piece of movies from N piece of DVDs that DuoDuo want to get the highest value and the time they cost not more then L.
How clever you are! Please help DuoDuo’s uncle.
 

 

Input
The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by input data for each test case:
The first line is: N(N <= 100),M(M<=N),L(L <= 1000)
N: the number of DVD that DuoDuo want buy.
M: the number of DVD that the shop can sale.
L: the longest time that her grandfather allowed to watch.
The second line to N+1 line, each line contain two numbers. The first number is the time of the ith DVD, and the second number is the value of ith DVD that DuoDuo rated.
 

 

Output
Contain one number. (It is less then 2^31.)
The total value that DuoDuo can get tonight.
If DuoDuo can’t watch all of the movies that her uncle had bought for her, please output 0.
 

 

Sample Input
1
3 2 10
11 100
1 2
9 1
 
Sample Output
3

 

    题意:

    给出T(1到10)个case,每个case首先给出三个数,N(0到100)个想买DVD,M(0到N)个商家最大允许购买量,L(0到1000)最大播放时间。

 

    思路:

    二维01背包。要求不超过M和不超过L的情况下,是总价值达到最高。注意初始dp赋值。

 

    AC:

#include<stdio.h>
#include<string.h>
#define max 1000000
int t[150],v[150];
int dp[150][1500];

int main()
{
    int test;
    scanf("%d",&test);
    while(test--)
    {
      int num,cho,time;

      for(int i=0;i<150;i++)
       for(int j=0;j<1500;j++)
       if(!i) dp[i][j]=0;
       else   dp[i][j]=-max;

      scanf("%d%d%d",&num,&cho,&time);

      for(int i=1;i<=num;i++)
        scanf("%d%d",&t[i],&v[i]);

      for(int i=1;i<=num;i++)
        for(int j=cho;j>=1;j--)
          for(int k=time;k>=t[i];k--)
          if(dp[j-1][k-t[i]]+v[i]>dp[j][k])
          dp[j][k]=dp[j-1][k-t[i]]+v[i];

      if(dp[cho][time]<0) printf("0\n");
      else printf("%d\n",dp[cho][time]);
    }
    return 0;
}

 

 

 

分享到:
评论

相关推荐

    WATCH THE UNOBSERVED_ A SIMPLE APPROACH TO PARALLELIZING

    WATCH THE UNOBSERVED_ A SIMPLE APPROACH TO PARALLELIZING

    watch the meteor shower with you

    NULL 博文链接:https://8214qiu.iteye.com/blog/1843523

    Swift Development for the Apple Watch.pdf

    Swift Development for the Apple Watch.pdf

    Swift.Development.for.the.Apple.Watch.149192520

    Apple Watch is the sort of science-fiction gadget that people used to dream about as kids. What kinds of apps do you envision for this new device? If you’re comfortable using OS X, Xcode, and iOS—...

    Apple Watch App Development(PACKT,2016)

    Apple Watch App Development introduces you to the architecture and possibilities of the Apple Watch platform, as well as an in-depth look at how to work with Xcode playgrounds. Benefit from a rapid ...

    BCB-program3.rar_The Watch

    This BCB program used the mask method by highbass, lowpass and Laplace to test bmp images and watch the results.

    xenbus_xs.rar_The Watch

    The thread waits on the watch_events_waitq for work to do (queued on watch_events list). When it wakes up it acquires the xenwatch_mutex before reading the list and carrying out work.

    Developing.for.Apple.Watch.2nd.Edition

    You'll learn how to display beautiful interfaces to the user, how to use the watch's heart rate monitor and other hardware features, and the best way to keep everything in sync across your users' ...

    image watch vs2017

    自己改的vs2017 image watch 自己改的vs2017 image watch

    cpu24-3-4_TheWatch_cpucc++_

    Watch the game source code written in the video and download it if necessary. Pure C

    八年级英语下册 Unit 8 Our Clothes Topic 3 Let’s go and watch the fashio

    八年级英语下册 Unit 8 Our Clothes Topic 3 Let’s go and watch the fashion show.学案及练习(无答案) 仁爱版

    ImageWatch.rar

    确保使用的是debug模式,并且在适当的位置设置的断点,在本例中在第二个for循环的位置以及第一个imshow的位置分别设置断点。 调试运行至断点时即可激活image watch插件。如果没有显示Image Watch窗口,可以使用如下...

    Apple Watch App Development

    Build real-world applications for the Apple Watch platform using the WatchKit framework and Swift 2.0 About This Book Find out how to download and install the Xcode development tools before learning ...

    LCD.zip_The Watch

    With this project works LCD driving very fast. I have make a little video about my ... in menu can you switch the output with ok taste. sry for my bad english https://www.youtube.com/watch?v=oZap468Ne-Y

    linux watch

    about IBM's Linux Watch,the latest technology in embed filed!

    jforum-2.1.8-src.zip_JForum-2.1.8_The Watch_jforum_jforum 2.1.8-

    Personally think is the best forum for the Java source code, open source, you can watch the official website of the latest developments http://www.jforum.net/

    a_plus_b.cpp

    输入 Input two integers A and B, process to the end of the file. (Watch the Sample Input) 输出 For each case, output A + B in one line.(Watch the Sample Output)

    ImageWatch vs2019

    ImageWatch插件,opencv好帮手,vs2019中使用

    ImageWatch2019.vsix

    解决目前imagewatch无法安装在vs2019上的问题,虽然会提示兼容问题,但亲测可以正常使用,资源里包含的ImageWatch正常安装就可以使用(需先安装VS2019),注:由于vs2019更新,已无法正常使用,还望谨慎下载。...

    Apple Watch要装的12个应用 Apple Watch必备App.pdf

    Apple Watch要装的12个应用 Apple Watch必备App.pdfApple Watch要装的12个应用 Apple Watch必备App.pdf

Global site tag (gtag.js) - Google Analytics