题意:在KTV唱歌剩下的t秒时间内,决定选最爱的n首歌中的一部分歌,在时间结束之前唱一首时长678秒的《劲歌金曲》,使得唱的总曲目尽量多(包括《劲歌金曲》),在此前提下尽量晚的离开KTV。(n<=50,t<=109)

分析:

1、输入保证所有n+1首曲子总长度严格大于t,虽然,t<=109,实际上t不会超过180n+678。

2、dp[i]剩余时间为i时唱的总曲目,time[i]剩余时间为i时唱歌时间总长度。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int dp[MAXT];
int time[MAXT];
int main(){
int T;
scanf("%d", &T);
int kase = 0;
while(T--){
int n, t;
scanf("%d%d", &n, &t);
memset(dp, 0, sizeof dp);
memset(time, 0, sizeof time);
int len = Min(t - 1, 180 * n);
for(int i = 0; i < n; ++i){
int x;
scanf("%d", &x);
for(int j = len; j >= 0; --j){
if(j >= x){
if(dp[j - x] + 1 > dp[j]){
dp[j] = dp[j - x] + 1;
time[j] = time[j - x] + x;
}
else if(dp[j - x] + 1 == dp[j]){
time[j] = Max(time[j], time[j - x] + x);
}
}
}
}
int ansnum = -1;
int anstime = 0;
for(int i = len; i >= 0; --i){
if(dp[i] > ansnum){
ansnum = dp[i];
anstime = time[i];
}
else if(dp[i] == ansnum){
anstime = Max(anstime, time[i]);
}
}
printf("Case %d: %d %d\n", ++kase, ansnum + 1, anstime + 678);
}
return 0;
}

  

最新文章

  1. .NET WEB程序员需要掌握的技能
  2. 数据结构-&gt;冒泡排序
  3. NetworkComms V3 使用TCP通信传递IList&lt;T&gt;类型的数据
  4. PHP 与pdf文档 与条码
  5. [2016.01.01]万峰文本处理专家 v2.0
  6. window常用命令
  7. Jenkins搭建
  8. Oracle 客户端配置
  9. 重定向 vs output redirect
  10. String类的split方法以及StringTokenizer
  11. ios创建画笔的样例(双笔画效果)
  12. postman定义公共函数
  13. 几个OOD概念
  14. 安装OpenSSL缺失Microsoft Visual C++ 2008 Redistributables的解决方案
  15. PHP-Iterator迭代器(遍历)接口详讲
  16. Coxph model Pvalue Select2
  17. Markdown语法简单介绍
  18. Dbvisualizer设置SQL语句自动提示
  19. linux 中更改权限命令chown,chmod,chgrp
  20. SQL Server开窗函数之OVER子句、PARTITION BY 子句

热门文章

  1. ES 模糊查询
  2. PHP7 源码整体框架
  3. python中软件开发规范,模块,序列化随笔
  4. Activity的生命周期及协同作用
  5. VUE - vuex state的使用
  6. 118.django中表单的使用方式
  7. SpringBoot学习(学习过程记录)
  8. 项目启动报错:Communications link failure
  9. Python中基于Unpacking与Packing进行分割,组合操作的嵌套元组数据结构的应用
  10. H5页面,百度地图点击事件