|
发表于 2011-7-10 16:13:55
|
显示全部楼层
- #include<stdio.h>
- #include<stdlib.h>
- #define N 1000
- //存放划分出来的整数
- //vec[0]为要划分的整数
- int vec[N];
- void work();
- void getPartition(int n, int pos);
- void print(int pos);
- int main(){
- while(scanf("%d",vec)!=EOF) work();
- }
- void work(){
- getPartition(vec[0],1);
- }
- void getPartition(int n,int pos){
- if(n>0){
- int i;
- for(i=min(n,vec[pos-1]);i>0;--i){
- vec[pos]=i;
- getPartition(n-i,pos+1);
- }
- }
- else print(pos);
- }
- void print (int pos){
- int i;
- printf("%d=%d",vec[0],vec[1]);
- for(i=2;i<pos;++i) printf("+%d",vec[i]);
- printf("\n");
- }
复制代码 |
|