当前位置:网站首页>2/13 review Backpack + monotonic queue variant
2/13 review Backpack + monotonic queue variant
2022-07-06 04:05:00 【Zhong Zhongzhong】
Looking back on these backpacks and greed , It's much simpler ……qaq
ordinary 01 Knapsack for the number of solutions :
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e4+5;;
int v,n,a[30],f[maxn];
signed main()
{
scanf("%lld%lld",&v,&n);
for(int i=1;i<=v;i++)
scanf("%lld",&a[i]);
f[0]=1;
for(int i=1;i<=v;i++)
{
for(int j=a[i];j<=n;j++)
f[j]=f[j]+f[j-a[i]];
}
cout<<f[n]<<endl;
return 0;
}
https://www.luogu.com.cn/problem/P1586
One more dimension is added : Several numbers are used to form this result
f[i][j]: Representation number i It was used j The number makes up
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+5;
const int M=32768;
int t,n,f[maxn][5];
signed main()
{
f[0][0]=1;
for(int i=1;i*i<=M;i++)
{
for(int j=i*i;j<=M;j++)
{
for(int k=1;k<=4;k++)
f[j][k]+=f[j-i*i][k-1];
}
}
scanf("%lld",&t);
while(t--)
{
int n,tmp=0;
scanf("%lld",&n);
for(int i=1;i<=4;i++)
tmp+=f[n][i];
cout<<tmp<<endl;
}
return 0;
}
https://www.luogu.com.cn/problem/P1638
Constantly update the value of the left endpoint , If the last position of the left endpoint is greater than the left endpoint , be left++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
int pos[2005],p[maxn],n,m,k;
signed main()
{
scanf("%lld%lld",&n,&m);
memset(pos,-1,sizeof(pos));
int l=1,ll=0,rr=0,ml=inf;
for(int i=1;i<=n;i++)
{
scanf("%lld",&p[i]);
if(pos[p[i]]==-1)
k++;
pos[p[i]]=i;
while(l!=i&&l<pos[p[l]])
l++;
if(k==m&&i-l+1<ml)
{
ml=i-l+1;
ll=l;
rr=i;
}
}
//cout<<ml<<endl;
cout<<ll<<" "<<rr<<endl;
return 0;
}
边栏推荐
- Database, relational database and NoSQL non relational database
- Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
- Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- MySQL reads missing data from a table in a continuous period of time
- [optimization model] Monte Carlo method of optimization calculation
- WPF effect Article 191 box selection listbox
- math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
- User datagram protocol UDP
- Why do you want to start pointer compression?
猜你喜欢
![P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]](/img/b1/dbfc42d66548476300501dd839abef.jpg)
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]

The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched

Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)

【FPGA教程案例11】基于vivado核的除法器设计与实现

TCP/IP协议里面的网关地址和ip地址有什么区别?

ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
![[meisai] meisai thesis reference template](/img/14/b39e1db0b5b35702508068e028ee5a.jpg)
[meisai] meisai thesis reference template

After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling

C#(三十)之C#comboBox ListView treeView

Viewing and verifying backup sets using dmrman
随机推荐
About some basic DP -- those things about coins (the basic introduction of DP)
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Hashcode and equals
[practice] mathematics in lottery
综合能力测评系统
Take you to wechat applet development in 3 minutes
C#(二十七)之C#窗体应用
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Fundamentals of SQL database operation
Simple blog system
绑定在游戏对象上的脚本的执行顺序
An article will give you a comprehensive understanding of the internal and external components of "computer"
C#(三十一)之自定义事件
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
使用JS完成一个LRU缓存
Python book learning notes - Chapter 09 section 01 create and use classes
C#(二十九)之C#listBox checkedlistbox imagelist
10个 Istio 流量管理 最常用的例子,你知道几个?