当前位置:网站首页>Array division (backpack)
Array division (backpack)
2022-04-22 05:37:00 【Bzdhxs_ nt】
Ideas
consider f [ i ] f[i] f[i] Said to i i i The maximum number of intervals that can be divided at the end
obviously When a [ i ] − a [ j ] > = b [ i ] − b [ j ] & & f [ j ] ! = − 1 a[i] - a[j] >= b[i] - b[j] \&\& f[j] != -1 a[i]−a[j]>=b[i]−b[j]&&f[j]!=−1 when
f [ i ] = m a x ( f [ j ] + 1 , f [ i ] ) , j ∈ [ 0 , i − 1 ] f[i] = max(f[j]+1,f[i]) ,j \in [0,i-1] f[i]=max(f[j]+1,f[i]),j∈[0,i−1]
Code
int f[5005]; // With n The maximum number of intervals that can be divided at the end
void solve(){
int n;cin>>n;
vector<int> a(n+1),b(n+1);
forr(i,1,n) cin>>a[i],a[i] += a[i-1];
forr(i,1,n) cin>>b[i],b[i] += b[i-1];
mem(f,-1);
f[0] = 0;
forr(i,1,n){
forr(j,0,i-1){
if(a[i] - a[j] >= b[i] - b[j] && f[j] != -1) f[i] = max(f[i],f[j]+1);
}
}
cout << f[n] << endl;
}
signed main()
{
int t;cin>>t;
while(t--) solve();
return 0;
}
版权声明
本文为[Bzdhxs_ nt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210617219402.html
边栏推荐
- unity接入ILRuntime之后 热更工程应用Packages下面的包方法 例如Unity.RenderPipelines.Core.Runtime包
- Unity built-in terrain optimization
- C language version: dynamic establishment of binary tree
- 再见2020,2021我来了
- Unity first order Bezier curve for throwing objects
- 2022.4.21-----leetcode. eight hundred and twenty-four
- C語言練習(2)——鏈錶實現多項式加法
- Kaggle_NBME NLP比赛Baseline详解(2)
- list stream: reduce的使用实例
- 2022年JS新增小技巧
猜你喜欢

Shenzhen Xishuangbanna
![[nanny installation tutorial] download MySQL 5 from the source code of Linux operating system seven](/img/1a/f2b3da4aa6df9deccf2d1376744b7a.png)
[nanny installation tutorial] download MySQL 5 from the source code of Linux operating system seven

Simulate the infectious disease model with MATLAB (only do matlab simulation learning and practice, not actual situation and application)

Kaggle_NBME NLP比赛Baseline详解(2)

Pratique du langage C (2) - - mise en oeuvre de l'addition polynomiale par liste liée

Network attack and Defense Security Learning Platform - upload key 3

MySQL数据库基础

C语言文件操作

Efficiency tool | special screenshot auxiliary software pureref

mysql中on duplicate key update 使用详解
随机推荐
Unity limits the rotation angle
Fundamentals of graphics - depth of field / DOF
GBase 8s V8. 8 SQL Guide: tutorial-5.3
IT配电及防火限流式保护器应用及选型
Xxxx (dynamic library name): cannot open shared object file: no such file or directory
【FedMD,一种利用模型蒸馏的异构FL训练方法】FedMD: Heterogenous Federated Learning via Model Distillation
Kaggle_NBME NLP比赛Baseline详解(2)
Use render texture to display 3D model animation on the UI
判断链表是否有环
The signal isolator is used in the water treatment control system to solve the problem of limitation due to some on-site non electric installation conditions
Fundamentals of graphics - Mobile GPU architecture
MySQL基础命令及练习题(一)
Unreal engine sequence effect and audio binding trigger
Network attack and Defense Security Learning Platform - upload key 3
The unreal engine uses loadclass to load the blueprint class
剑指 Offer 22. 链表中倒数第k个节点
strlen的三种实现方法你知道吗?
Obdumper common export commands
Auto. JS canvas setting anti aliasing paint setAntiAlias(true);
Pratique du langage C (2) - - mise en oeuvre de l'addition polynomiale par liste liée