[ABC263C] Monotonically Increasing

Notes

For two integer sequences of the same length $A_1,A_2,\dots,A_N$ and $B_1,B_2,\dots,B_N$, $A$ is said to be lexicographically earlier than $B$ if and only if:

  • there is an integer $i$ $(1 \le i \le N)$ such that $A_j=B_j$ for all integers $j$ satisfying $1 \le j < i$, and $A_i < B_i$.

An integer sequence $A_1,A_2,\dots,A_N$ is said to be strictly increasing if and only if:

  • $A_i < A_{i+1}$ for all integers $i$ $(1 \le i \le N-1)$.

Constraints

  • $1 \le N \le M \le 10$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$

Output

Print the sought sequences in lexicographically ascending order, each in its own line (see Sample Outputs).


Sample Input 1

2 3

Sample Output 1

1 2 
1 3 
2 3 

The sought sequences are $(1,2),(1,3),(2,3)$, which should be printed in lexicographically ascending order.


Sample Input 2

3 5

Sample Output 2

1 2 3 
1 2 4 
1 2 5 
1 3 4 
1 3 5 
1 4 5 
2 3 4 
2 3 5 
2 4 5 
3 4 5 

爆搜出所有符合要求的排列。

#include<cstdio>
int n,m,st[15];
void dfs(int x,int lst)
{
	if(x>n)
	{
		for(int i=1;i<=n;i++)
			printf("%d ",st[i]);
		putchar('\n');
		return;
	}
	for(int i=lst+1;i<=m;i++)
	{
		st[x]=i;
		dfs(x+1,i);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	dfs(1,0);
}
posted @ 2022-09-27 21:41  灰鲭鲨  阅读(43)  评论(0编辑  收藏  举报