当前位置:网站首页>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;
}
边栏推荐
- How to standardize the deployment of automated testing?
- Detailed explanation of serialization and deserialization
- C#(二十七)之C#窗体应用
- 关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
- The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
- [001] [stm32] how to download STM32 original factory data
- Benefits of automated testing
- Maxay paper latex template description
- Database, relational database and NoSQL non relational database
- Mathematical modeling regression analysis relationship between variables
猜你喜欢
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
User datagram protocol UDP
IDEA编译JSP页面生成的class文件路径
How does technology have the ability to solve problems perfectly
Blue Bridge Cup - day of week
[Massey] Massey font format and typesetting requirements
Database, relational database and NoSQL non relational database
Redis (replicate dictionary server) cache
[Key shake elimination] development of key shake elimination module based on FPGA
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
随机推荐
Blue Bridge Cup - day of week
绑定在游戏对象上的脚本的执行顺序
No qualifying bean of type ‘......‘ available
1291_Xshell日志中增加时间戳的功能
2/11 matrix fast power +dp+ bisection
【按键消抖】基于FPGA的按键消抖模块开发
[Massey] Massey font format and typesetting requirements
C (XXIX) C listbox CheckedListBox Imagelist
Determine which week of the month the day is
Web components series (VII) -- life cycle of custom components
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
[practice] mathematics in lottery
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
mysql关于自增长增长问题
MySQL transaction isolation level
Ks008 SSM based press release system
Align items and align content in flex layout
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
Mathematical modeling regression analysis relationship between variables
Custom event of C (31)