最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

【SSE

互联网 admin 20浏览 0评论

【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);
}
发布评论

评论列表 (0)

  1. 暂无评论