CH0301解题报告
GossWandering · · 个人记录
注:
题目大意:
- 从
1 ~n 中选任意数,输出可能的所有方案。
思路:递归练手题(练习打字???)
#include<bits/stdc++.h>
#define ll long long
#define landingyu work();
#define AK return
#define IOI 0;
#define inf 0x3f3f3f3f
#define eps 0.00001
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int F[1000];
void write(int x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)write(x/10);
putchar(x%10+'0');
}
using namespace std;
int n;
vector <int> chosen;
void calc(int x){
if(x==n+1){
for(int i=0;i<chosen.size();i++) cout<<chosen[i]<<" ";
cout<<endl;
return;
}
calc(x+1);
chosen.push_back(x);
calc(x+1);
chosen.pop_back();
}
void work(){
n=read();
calc(1);
}
int main(){landingyu AK IOI}
老老实实打就行了啊。
不过我还是从书中学到了一点点新花样: