admin管理员组文章数量:1026989
【SSE
##Question
满足特异条件的数列。输入m和n(20≥m≥n≥0),求出满足以下方程式的正整数数列i1,i2,…,in,使得i1+i2+…+in=m,且i1≥i2≥…≥in。例如:
当n=4,m=8时,将得到如下5个数列:
5 1 1 1 4 2 1 1 3 3 1 1 3 2 2 1 2 2 2 2
**输入格式要求:“%d” 提示信息:“Please enter requried terms (<=10):”
" their sum:"
**输出格式要求:“There are following possible series:\n” “[%d]:” “%d”
程序运行示例1:
Please enter requried terms (<=10): 4 8
their sum:There are following possible series:
[1]:5111
[2]:4211
[3]:3311
[4]:3221
[5]:2222
程序运行示例2:
Please enter requried terms (<=10):4 10
their sum:There are following possible series:
##Code
#include <stdio.h>int num[11];int count = 0;
void dfs(int n, int now, int m, int max){if(now==n){if(max>=m&&m>=1){num[n] = m;count++;printf("[%d]:",count);for(int i=1; i<=n; i++){printf("%d",num[i]);}printf("\n");}return;}for(int i=max; i>=m/(n-now+1); i--){num[now] = i;dfs(n, now+1, m-i, i);}
}int main(){printf("Please enter requried terms (<=10):");int n,m;scanf("%d %d",&n, &m);printf(" their sum:");printf("There are following possible series:\n");dfs(n,1,m,m-n+1);
}
【SSE
##Question
满足特异条件的数列。输入m和n(20≥m≥n≥0),求出满足以下方程式的正整数数列i1,i2,…,in,使得i1+i2+…+in=m,且i1≥i2≥…≥in。例如:
当n=4,m=8时,将得到如下5个数列:
5 1 1 1 4 2 1 1 3 3 1 1 3 2 2 1 2 2 2 2
**输入格式要求:“%d” 提示信息:“Please enter requried terms (<=10):”
" their sum:"
**输出格式要求:“There are following possible series:\n” “[%d]:” “%d”
程序运行示例1:
Please enter requried terms (<=10): 4 8
their sum:There are following possible series:
[1]:5111
[2]:4211
[3]:3311
[4]:3221
[5]:2222
程序运行示例2:
Please enter requried terms (<=10):4 10
their sum:There are following possible series:
##Code
#include <stdio.h>int num[11];int count = 0;
void dfs(int n, int now, int m, int max){if(now==n){if(max>=m&&m>=1){num[n] = m;count++;printf("[%d]:",count);for(int i=1; i<=n; i++){printf("%d",num[i]);}printf("\n");}return;}for(int i=max; i>=m/(n-now+1); i--){num[now] = i;dfs(n, now+1, m-i, i);}
}int main(){printf("Please enter requried terms (<=10):");int n,m;scanf("%d %d",&n, &m);printf(" their sum:");printf("There are following possible series:\n");dfs(n,1,m,m-n+1);
}
本文标签: SSE
版权声明:本文标题:【SSE 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/IT/1686751370a32902.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论