当前位置:网站首页>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;
}
边栏推荐
- Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- Record an excel xxE vulnerability
- AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
- Unity中几个重要类
- Stack and queue
- 自动化测试怎么规范部署?
- ESP32_ FreeRTOS_ Arduino_ 1_ Create task
- Fundamentals of SQL database operation
- Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
猜你喜欢

MySQL about self growth

Solution to the problem that the root account of MySQL database cannot be logged in remotely

20、 EEPROM memory (AT24C02) (similar to AD)

Record the pit of NETCORE's memory surge

JVM的手术刀式剖析——一文带你窥探JVM的秘密

IDEA编译JSP页面生成的class文件路径

【按鍵消抖】基於FPGA的按鍵消抖模塊開發
![[disassembly] a visual air fryer. By the way, analyze the internal circuit](/img/73/29553d60f47deadfff420be40b7f77.jpg)
[disassembly] a visual air fryer. By the way, analyze the internal circuit
![[FPGA tutorial case 11] design and implementation of divider based on vivado core](/img/39/f337510c2647d365603a8485583a20.png)
[FPGA tutorial case 11] design and implementation of divider based on vivado core
![[adjustable delay network] development of FPGA based adjustable delay network system Verilog](/img/82/7ff7f99f5164f91fab7713978cf720.png)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
随机推荐
[FPGA tutorial case 11] design and implementation of divider based on vivado core
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
IDEA编译JSP页面生成的class文件路径
What is the difference between gateway address and IP address in tcp/ip protocol?
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
MySql數據庫root賬戶無法遠程登陸解决辦法
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical modeling regression analysis relationship between variables
Differential GPS RTK thousand search
Fundamentals of SQL database operation
使用JS完成一个LRU缓存
Interface idempotency
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
An article will give you a comprehensive understanding of the internal and external components of "computer"
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
Basic knowledge of binary tree, BFC, DFS