回归的第一篇就是深搜。
题目描述
从p个数字中取n个数,组成有重复的全排列的数,一行一个。
输入
5 3
输出
111
112
113
。。
。。
554
太简单了,有手就行。
这时就有人要问了,坤老师没手行吗?
我只能说“用脚”。
#include<bits/stdc++.h>
using namespace std;
int p,n;
void dfs(int c,int s)
{
if(c==n)
{
cout<<s<<endl;
return;
}
for(int i=1;i<=p;++i)
{
dfs(c+1,s*10+i);
}
}
int main(){
cin>>p>>n;
dfs(0,0);
return 0;
}
好了,886~~~~~~~~~~