当前位置:网站首页>Usaco3.4 "broken Gong rock" band raucous rockers - DP
Usaco3.4 "broken Gong rock" band raucous rockers - DP
2022-07-05 20:23:00 【Dimple】
https://www.luogu.com.cn/problem/P2736
The question
Given N ( 1 ≤ N ≤ 20 ) N(1\leq N\leq 20) N(1≤N≤20) song , Choose several songs from them , issue M ( 1 ≤ M ≤ 20 ) M(1\leq M\leq 20) M(1≤M≤20) Zhang CD.
Each sheet CD At most T ( 1 ≤ T ≤ 20 ) T(1\leq T\leq 20) T(1≤T≤20) Minutes of music , One song cannot be divided into two CD in .CD The quantity can be used up , It can also be done .
Choose according to the following criteria :
- Songs must be written in chronological order in all CD Appear on the disk .( notes : The first i i i The creation time of the last song of Zhang pan is earlier than that of i + 1 i+1 i+1 The first song of the disc )
- Select as many songs as possible .
ask , Can be installed M M M Zhang CD The maximum number of songs ?
Ideas
“ Songs must be written in chronological order in all CD Appear on the disk ” This condition shows that you can't be greedy directly .
Consider using dp, The maximum number of songs that can be stored in the current capacity is transferred from the capacity minus the current song size .
and “ One song cannot be divided into two CD in ” This condition indicates that you cannot simply transfer from the previous capacity , We also need to consider whether to pack it in two pieces .
therefore , Define the State f[i, j, k] Express , For the former i A song , Before use j Zhang CD Plus k minute , The maximum number of songs that can be accommodated .
Then the final state is f[n, m, 0].
State shift :
- First, inherit the state of the previous position :
f[i, j, k] = f[i-1, j, k]; - When additional
kMinutes is greater than the current song size , You can start fromf[i-1, j, k-a[i]To transfer :f[i, j, k] = f[i-1, j, k-a[i]] + 1; - otherwise , It needs to be stored in the previous record , from
f[i-1, j-1, t-a[i]]To transfer :f[i, j, k] = f[i-1, j-1, t-a[i]] + 1;
Code
#include<bits/stdc++.h>
using namespace std;
const int N = 210, mod = 1e9+7;
int T, n, m;
int a[N];
int f[N][N][N];
signed main(){
int t;
cin >> n >> t >> m;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
for(int k=0;k<=t;k++)
{
f[i][j][k] = f[i-1][j][k];
if(k>=a[i]) f[i][j][k] = max(f[i][j][k], f[i-1][j][k-a[i]] + 1);
else if(t-a[i] >= 0 && j >= 1) f[i][j][k] = max(f[i][j][k], f[i-1][j-1][t-a[i]] + 1);
}
}
}
cout << f[n][m][0];
return 0;
}
Experience
State definition should dare to think .
边栏推荐
猜你喜欢

零道云新UI设计中

【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程

Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)

Introduction to dead letter queue (two consumers, one producer)
![[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design](/img/92/7af0db21b3d7892bdc5dce50ca332e.png)
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design

.Net分布式事務及落地解决方案

鸿蒙os第四次学习

2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办

关于BRAM IP复位的优先级

【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
随机推荐
Leetcode brush question: binary tree 13 (the same tree)
nprogress插件 进度条
Ffplay document [easy to understand]
Scala basics [HelloWorld code parsing, variables and identifiers]
.Net分布式事务及落地解决方案
Leetcode(347)——前 K 个高频元素
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
微信小程序正则表达式提取链接
How to retrieve the root password of MySQL if you forget it
【刷题记录】1. 两数之和
实操演示:产研团队如何高效构建需求工作流?
Unity editor extended UI control
Mysql频繁操作出现锁表问题
鸿蒙系统控制LED的实现方法之经典
Is it safe for CICC fortune to open an account online?
DP:树DP
Scala基础【HelloWorld代码解析,变量和标识符】
leetcode刷题:二叉树10(完全二叉树的节点个数)
鸿蒙os第四次学习