当前位置:网站首页>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;
}
边栏推荐
- Interface idempotency
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- MySQL about self growth
- math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- Thread sleep, thread sleep application scenarios
- Hashcode and equals
- Use js to complete an LRU cache
- 判断当天是当月的第几周
- [Massey] Massey font format and typesetting requirements
猜你喜欢
TCP/IP协议里面的网关地址和ip地址有什么区别?
C form application of C (27)
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Class A, B, C networks and subnet masks in IPv4
【leetcode】1189. Maximum number of "balloons"
在 .NET 6 中使用 Startup.cs 更简洁的方法
记一次excel XXE漏洞
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
In Net 6 CS more concise method
MySQL master-slave replication
随机推荐
【按键消抖】基于FPGA的按键消抖模块开发
Class A, B, C networks and subnet masks in IPv4
IDEA编译JSP页面生成的class文件路径
[practice] mathematics in lottery
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
[optimization model] Monte Carlo method of optimization calculation
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Do you know cookies, sessions, tokens?
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL reads missing data from a table in a continuous period of time
2/12 didn't learn anything
Thread sleep, thread sleep application scenarios
MySQL 中的数据类型介绍
Database, relational database and NoSQL non relational database
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
C (thirty) C combobox listview TreeView
Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]
lora网关以太网传输