AT_abc473_d 题解
很多 dsa 说这题很难卡之类,甚至有金钩 dsa AK 后在 qqm 群发表感言:
头像和用户名进行了打码处理,但是大家应该都能猜出来是谁说的(?
但是我感觉这题真的还好啊。
我们首先发现
怎么办怎么办,我可不想在 D 就上高科技,我们只能考虑剪枝了。首先是最显然的剪枝——不能让当前总和超过
然后还能发现一个性质,就是当我们已经把前
大胆开写,然后你就会:
时间复杂度的话呢,前面就说过了题目保证满足条件的序列数只有
::::success[code && submission]
#include<bits/stdc++.h>
#define LL long long
#define UInt unsigned int
#define ULL unsigned long long
#define LD long double
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define pDD pair<LD,LD>
#define fr first
#define se second
#define pb push_back
#define isr insert
#define _i128 __int128
using namespace std;
int n,k,p[15];
int read(){
int su=0,pp=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')pp=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){su=su*10+ch-'0';ch=getchar();}
return su*pp;
}
void DFS(int u,int k){
if(u>n){
if(k)return;
for(int i=1;i<=n;i++)cout<<p[i]<<" ";
cout<<"\n";return;
}
if(u==n){
if(k%n!=0)return;
p[n]=k/n;DFS(u+1,0);
return;
}
for(int x=0;x*u<=k;x++){
p[u]=x;
DFS(u+1,k-x*u);
p[u]=0;
}return;
}
int main(){
n=read(),k=read();
DFS(1,k);
return 0;
}
::::
如果本篇题解对你有帮助的话,麻烦你点一个小小的赞,真是太感谢啦!