每周打卡 第二(?)周 5

 

 

 

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 30;

int m,n;

int st[N];
bool a[N];

void f(int u,int t)
{
if(u > m)
{
for(int i = 1;i <= m;i ++ )
{
printf("%d ",st[i]);
}
printf("\n");

}

else
for(int i = t;i <= n;i ++ ) // int i = t
{
if(u==1 && i + m - 1 > n ) break; //无关
if(!a[i])
{
st[u] = i;
a[i] = 1;
f(u + 1,i + 1);// f(, i + 1) ?
if(u > 1) // 无关
a[i] = 0;
}
}

}

int main()
{
cin >> n >> m;

f(1,1);

return 0;
}

 

 

 

 

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 16 ;

int n;
int st[N];

void f(int u)
{

if(u > n)
{
for( int i = 1 ; i <= n ; i ++ )
{
if(st[i] == 1) printf("%d ",i);
}
printf("\n");

return;
}

st[u] = 1;
f(u + 1);
st[u] = 2;

st[u] = 2;
f(u + 1);
st[u] = 2;

}
int main()
{
scanf("%d",&n);

f(1);

return 0;
}

posted @ 2023-05-05 22:06  poemgranate  阅读(15)  评论(0)    收藏  举报