您现在的位置是:主页 > news > 网站外链软件/外汇seo公司

网站外链软件/外汇seo公司

admin2025/6/14 0:32:40news

简介网站外链软件,外汇seo公司,微信小程序开发教程书,xuezuo网站建设题见洛谷 带有技巧的搜索&#xff0c;用到杨辉三角形 不难看出 第几个&#xff08;k&#xff09;拆的数&#xff08;虽说并不是拆的&#xff09;&#xff0c;系数为杨辉三角第n行&#xff0c;第k列的数字 #include<iostream> #include<cstdio> #include<cstrin…

网站外链软件,外汇seo公司,微信小程序开发教程书,xuezuo网站建设题见洛谷 带有技巧的搜索&#xff0c;用到杨辉三角形 不难看出 第几个&#xff08;k&#xff09;拆的数&#xff08;虽说并不是拆的&#xff09;&#xff0c;系数为杨辉三角第n行&#xff0c;第k列的数字 #include<iostream> #include<cstdio> #include<cstrin…

题见洛谷
带有技巧的搜索,用到杨辉三角形

这里写图片描述
不难看出 第几个(k)拆的数(虽说并不是拆的),系数为杨辉三角第n行,第k列的数字

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int n,sum,a[124];
int yh[20][20];
bool f[20]; 
void dfs(int k,int tot)
{//if(tot>sum) return;if(k==n+1){if(tot==sum){for(int i=1;i<=n;i++)printf("%d ",a[i]);exit(0);}return;}for(int i=1;i<=n;i++){if(tot+i*yh[n][k]<=sum)if(!f[i]){a[k]=i;f[i]=true;dfs(k+1,tot+i*yh[n][k]);a[k]=0;f[i]=false;//回溯! }}}
int main()
{scanf("%d%d",&n,&sum);yh[1][1]=1;for(int i=2;i<=n;i++)for(int j=1;j<=i;j++)yh[i][j]=yh[i-1][j-1]+yh[i-1][j];/*for(int i=1;i<=n;i++){printf("%d ",yh[n][i]);}*/dfs(1,0);return 0;
} 

转载于:https://www.cnblogs.com/dfsac/p/6819777.html