0%

abc382-d 题解

比较简单的暴力搜索

直接搜就行了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;
int m,n,cnt;
int ans[20];
void cpt(int i,int pre){
for(int j=pre+10;(n-i)*10+j<=m;j++){
//ans[i]=j;
if(i==n){
cnt++;
}else{
cpt(i+1,j);
}
}
}
void dfs(int i,int pre){
for(int j=pre+10;(n-i)*10+j<=m;j++){
ans[i]=j;
if(i==n){
for(int k=1;k<=n;k++){
cout<<ans[k]<<" ";
}
cout<<endl;
}else{
dfs(i+1,j);
}

}
}
int main(){
ios::sync_with_stdio(0);
cout.tie(0);
cin>>n>>m;
cpt(1,-9);
cout<<cnt<<endl;
dfs(1,-9);
return 0;
}