当前位置:网站首页>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 .
边栏推荐
猜你喜欢

解决php无法将string转换为json的办法

小程序事件绑定

B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05

Practical demonstration: how can the production research team efficiently build the requirements workflow?

Enter the parallel world

【刷题记录】1. 两数之和

Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)

CTF reverse Foundation

无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...

Leetcode skimming: binary tree 16 (path sum)
随机推荐
Some problems encountered in cocos2d-x project summary
ROS2专题【01】:win10上安装ROS2
计算lnx的一种方式
Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
. Net distributed transaction and landing solution
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
Go language | 01 wsl+vscode environment construction pit avoidance Guide
Codeforces Round #804 (Div. 2) - A, B, C
Ros2 topic [01]: installing ros2 on win10
Summer Challenge harmonyos - realize message notification function
Scala基础【HelloWorld代码解析,变量和标识符】
Go language learning tutorial (16)
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
Leetcode skimming: binary tree 16 (path sum)
ffplay文档[通俗易懂]
物联网智能家居基本方法实现之经典
Unity编辑器扩展 UI控件篇
信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
Fundamentals - configuration file analysis
小程序项目结构