【2016杭电女生赛1002】【排列组合 隔板法】Desert 对n做正整序列拆分的方案数

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
#include<assert.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int main()
{
    int T; scanf("%d", &T); assert(T >= 1 && T <= 10);
    while (T--)
    {
        int n; scanf("%d", &n); assert(n >= 1 && n <= 1e6);
        putchar('1');
        while (--n) putchar('0');
        puts("");
    }
    return 0;
}
/*
【题意】
一开始有数量为n(1<=n<=1e6)的水,
我们每天可以喝数量为任意整数的水,问你有多少种方式可以把水喝完。

【类型】
简单排列组合 隔板法

【分析】
这道题其实就是——
问你,对于整数n,可以把n拆分成多少个不同的正整数序列
我们考虑排列组合中的隔板法。
就是n个数,中间有n-1个空位,
其中每一个空位中,都可以选择插入隔板,从而把这n个数分成若干份,恰好对应本题。

显然——
如果拆成1份,方案数是C(n-1,1-1)=C(n-1,0)
如果拆成2份,方案数是C(n-1,2-1)=C(n-1,1)
如果拆成3份,方案数是C(n-1,3-1)=C(n-1,2)
...
如果拆成n份,方案数是C(n-1,n-1)=C(n-1,n-1)
对应着二项式展开,它们的和恰好是2^(n-1)。
于是对应着,我们直接输出——
 1个1
+(n-1)个0即可。

【时间复杂度&&优化】
O(n)

*/


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值