当前位置:网站首页>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;
}
边栏推荐
- MySQL master-slave replication
- [meisai] meisai thesis reference template
- C#(二十九)之C#listBox checkedlistbox imagelist
- P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
- Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
- ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
- Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
- Fundamentals of SQL database operation
猜你喜欢
KS003基于JSP和Servlet实现的商城系统
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
Security xxE vulnerability recurrence (XXe Lab)
C#(三十一)之自定义事件
Class A, B, C networks and subnet masks in IPv4
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
DM8 archive log file manual switching
lora网关以太网传输
[meisai] meisai thesis reference template
随机推荐
TCP/IP协议里面的网关地址和ip地址有什么区别?
MySql数据库root账户无法远程登陆解决办法
How to modify field constraints (type, default, null, etc.) in a table
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
阿里测试师用UI自动化测试实现元素定位
SSTI template injection explanation and real problem practice
lora网关以太网传输
Ks008 SSM based press release system
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
C#(三十)之C#comboBox ListView treeView
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
1291_Xshell日志中增加时间戳的功能
Python book learning notes - Chapter 09 section 01 create and use classes
有条件地 [JsonIgnore]
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
[Massey] Massey font format and typesetting requirements
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
Stack and queue
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error: