请问有多少个序列满足下面的条件: 1.序列的长度为 5。 2.序列中的每个数都是 1 到 10 之间的整数。 3.序列中后面的数大于等于前面的数。

请问有多少个序列满足下面的条件:

1.序列的长度为 5。

2.序列中的每个数都是 1 到 10 之间的整数。

3.序列中后面的数大于等于前面的数。

如果=10,则为2002

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int cnt=0;
	for(int i=1;i<=10;i++){
    
    
		for(int j=1;j<=10;j++){
    
    
			for(int k=1;k<=10;k++){
    
    
				for(int l=1;l<=10;l++){
    
    
					for(int x=1;x<=10;x++){
    
    
						if(i<=j&&j<=k&&k<=l&&l<=x){
    
    
							cnt++;
						}
					}
				}
			}
		}
	}
	cout<<cnt;//  2002
	return 0;
}

如果≠10,则为1286

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int cnt=0;
	for(int i=1;i<10;i++){
    
    
		for(int j=1;j<10;j++){
    
    
			for(int k=1;k<10;k++){
    
    
				for(int l=1;l<10;l++){
    
    
					for(int x=1;x<10;x++){
    
    
						if(i<=j&&j<=k&&k<=l&&l<=x){
    
    
							cnt++;
						}
					}
				}
			}
		}
	}
	cout<<cnt;// 1287
	return 0;
}

猜你喜欢

转载自blog.csdn.net/xuexiwd/article/details/114904436
今日推荐