`
Simone_chou
  • 浏览: 192589 次
  • 性别: 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 meteor shower with you

    标题“watch the meteor shower with you”可能并非一个典型的IT主题,但考虑到标签中提到了“源码”和“工具”,我们可以推测这篇博文可能是关于一种编程工具或者代码实践的分享。由于描述部分是“NULL”,没有提供...

    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

    vs2017-ImageWatch.zip

    《Visual Studio 2017中的Image Watch插件:离线安装详解》 在软件开发过程中,调试是不可或缺的一环,尤其是对于处理图像数据时,更需要强大的工具辅助。Visual Studio 2017(简称VS2017)作为微软推出的强大IDE,...

    ImageWatch2019.vsix

    在OpenCV中,也有一个小插件可以实现类似于Halcon的实时显示功能,不必为了查看运行过程图像而在代码中插入N个imshow函数了,这个插件就是Image Watch。 Image Watch是Microsoft Visual Studio(不是OpenCV小组)...

    cloudwatch_exporter, Amazon AWS CloudWatch的度量出口.zip

    cloudwatch_exporter, Amazon AWS CloudWatch的度量出口 CloudWatch导出程序Amazon CloudWatch的导出器。构建和运行要生成的mvn package 。java -jar target/cloudwatch_exporter-*-SNAPSHOT-jar-with-

    ImageWatch vs2019

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

    AppleWatch工程图纸

    CAD技术是现代工业设计中的核心工具,它允许设计师通过计算机软件创建、修改和分析产品的三维模型。在Apple Watch的案例中,CAD工程图是产品设计团队在设计过程中的关键文档,它们详尽地展示了每一部分的精确尺寸、...

    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

    NewWatch.zip

    "NewWatch"是固高科技GTS VB系列中的一项特色功能,它允许用户实时监控和调试控制系统,提升设备运行的稳定性和效率。 在描述中提到的"NewWatch功能例程",是一种编程示例,旨在帮助开发者或工程师了解如何利用32位...

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

    Apple Watch作为苹果公司的一款智能穿戴设备,拥有众多第三方应用程序,为用户提供各种便利。以下是对描述中提到的12个Apple Watch必备应用的详细介绍: 1. **Roomie Remote**:这是一款能够将你的Apple Watch变成...

    ImageWatch VS2019 安装,OpenCV调试插件

    "ImageWatch VS2019"和"OpenCV"是两个这样的工具,它们为开发者提供了强大的功能和便利。本文将详细介绍这两个工具的安装过程以及如何在Visual Studio 2019中进行调试。 首先,我们关注"ImageWatch2019.vsix",这是...

Global site tag (gtag.js) - Google Analytics