poj3187 暴力+杨辉三角

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

int a[12][12],b[12],c[12];

int main(){

int n,sum,answ;

a[1][1] = 1;

for(int i = 2;i<=10;++i){

for(int j = 1;j<=i;++j){

if(j == 1||j == i)

a[i][j] = 1;

else

a[i][j] = a[i-1][j] + a[i-1][j-1];

}

}

while(cin>>n>>sum){

for(int i = 1;i<=n;++i)

b[i] = i;

do{

answ = 0;

for(int i = 1;i<=n;++i)

answ += b[i]*a[n][i];

if(answ == sum) break;

}while(next_permutation(b+1,b+n+1));

for(int i = 1;i<=n;++i){

if(i != n)

cout<<b[i]<<” “;

else

cout<<b[i]<<endl;

}

}

return 0;

}

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/dukig/article/details/79304489
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞