定制建站 app建设,网站建设价格比较,semiconductor是什么意思,接网站开发的公司问题描述 小武老师特别喜欢吃烤全羊#xff0c;小武老师吃烤全羊很特别#xff0c;为什么特别呢#xff1f;因为他有 1010 种配料#xff08;芥末、孜然等#xff09;#xff0c;每种配料可以放 11 到 33 克#xff0c;任意烤全羊的美味程度为所有配料质量之和。
现在小武老师吃烤全羊很特别为什么特别呢因为他有 1010 种配料芥末、孜然等每种配料可以放 11 到 33 克任意烤全羊的美味程度为所有配料质量之和。
现在 小武老师想要知道如果给你一个美味程度 nn 请输出这 1010 种配料的所有搭配方案。
输入格式 一个正整数 nn 表示美味程度。
输出格式 第一行方案总数。
第二行至结束1010 个数表示每种配料所放的质量按字典序排列。
如果没有符合要求的方法就只要在第一行输出一个 00。
输入数据 1 11 输出数据 1 10 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 数据范围与约定 对于 100%100% 的数据n \leq 5000n≤5000 。
代码:
#includebits/stdc.h
using namespace std;
int n, cnt, a[10000][10], b[1001];
void dfs(int step, int sum) { int i;if (step 10) { if (sum n) {for (i 0; i 10; i)a[cnt][i] b[i]; cnt; }return;}for (i 1; i 4; i) { b[step] i; dfs(step 1, sum i); }
}
int main() {int i, j;cin n;dfs(0, 0);if (!cnt)cout 0;else { cout cnt endl; for (i 0; i cnt; i) { for (j 0; j 10; j)cout a[i][j] ;cout endl; }}return 0;
}