侧边栏壁纸
博主头像
王小木人

这是很长,很好的一生

  • 累计撰写 141 篇文章
  • 累计创建 43 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

抽签

王小木人
2021-05-22 / 0 评论 / 0 点赞 / 843 阅读 / 507 字

X星球要派出一个5人组成的观察团前往W星。
其中:
A国最多可以派出4人。
B国最多可以派出2人。
C国最多可以派出2人。
D国最多可以派出1人。
E国最多可以派出1人。
F国最多可以派出3人。

那么最终派往W星的观察团会有多少种国别的不同组合呢?

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
    int a[]={4,2,2,1,1,3};
    void fun(int[],int,int,string);
    fun(a,0,5,"");
return 0;
}
void fun(int a[],int k,int n,string s)
{
if(k==6)
{
if(n==0)


    cout<<s<<'\n';
    return;


}
string s2=s;
for(int i=0;i<=a[k];i++)
{
fun(a,k+1,n-i,s2);
s2+=(char)(k+'A');
}
}
0

评论区