当前位置:网站首页>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;
}
边栏推荐
- C form application of C (27)
- MySql數據庫root賬戶無法遠程登陸解决辦法
- Python book learning notes - Chapter 09 section 01 create and use classes
- Alibaba testers use UI automated testing to achieve element positioning
- An article will give you a comprehensive understanding of the internal and external components of "computer"
- Path of class file generated by idea compiling JSP page
- 判断当天是当月的第几周
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- [American competition] mathematical terms
- Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
猜你喜欢
Path of class file generated by idea compiling JSP page
C (XXIX) C listbox CheckedListBox Imagelist
Interface idempotency
Align items and align content in flex layout
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
Thread sleep, thread sleep application scenarios
Redis (replicate dictionary server) cache
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
10個 Istio 流量管理 最常用的例子,你知道幾個?
Record the pit of NETCORE's memory surge
随机推荐
Basic knowledge of binary tree, BFC, DFS
Hashcode and equals
Prime protocol announces cross chain interconnection applications on moonbeam
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
阿里测试师用UI自动化测试实现元素定位
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
记一次excel XXE漏洞
MySQL about self growth
使用JS完成一个LRU缓存
cookie,session,Token 这些你都知道吗?
IDEA编译JSP页面生成的class文件路径
Leetcode32 longest valid bracket (dynamic programming difficult problem)
C language -- structs, unions, enumerations, and custom types
asp. Core is compatible with both JWT authentication and cookies authentication
登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
TCP/IP协议里面的网关地址和ip地址有什么区别?
Solution to the problem that the root account of MySQL database cannot be logged in remotely
【leetcode】22. bracket-generating
Introduction to data types in MySQL