码迷,mamicode.com
首页 > 其他好文 > 详细

18.04.11 luoguP1025 数的划分

时间:2018-04-11 18:09:39      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:scan   one   show   多少   ide   stream   include   art   open   

题目描述

将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序)。

例如:n=7,k=3,下面三种分法被认为是相同的。

1,1,5; 1,5,1; 5,1,1;

问有多少种不同的分法。

输入输出格式

输入格式:

 

n,k (6<n<=200,2<=k<=6)

 

输出格式:

 

一个整数,即不同的分法。

 

输入输出样例

输入样例#1: 
7 3
输出样例#1: 
4

说明

四种分法为:1,1,5;1,2,4;1,3,3;2,2,3;

技术分享图片
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <algorithm>
 5 #include <stdlib.h>
 6 
 7 using namespace std;
 8 int count0=0,n,k;//n num k part
 9 
10 void dfs(int n,int part,int t){
11     if(t==k-1&&n-part>=part)count0++;
12     if(t==k-1)return;
13     for(int i=part;i<=n-part;i++)
14         dfs(n-part,i,t+1);
15 }
16 
17 int main()
18 {
19     scanf("%d%d",&n,&k);
20     for(int i=1;i<=n/2;i++)
21         dfs(n,i,1);
22     printf("%d\n",count0);
23     return 0;
24 }
View Code

18.04.11 luoguP1025 数的划分

标签:scan   one   show   多少   ide   stream   include   art   open   

原文地址:https://www.cnblogs.com/yalphait/p/8797020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!