Partition

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 842    Accepted Submission(s): 478

Problem Description
How many ways can the numbers 1 to 15 be added together to make 15? The technical term for what you are asking is the "number of partition" which is often called P(n). A partition of n is a collection of positive integers (not necessarily distinct) whose sum equals n.

Now, I will give you a number n, and please tell me P(n) mod 1000000007.

 

Input
The first line contains a number T(1 ≤ T ≤ 100), which is the number of the case number. The next T lines, each line contains a number n(1 ≤ n ≤ 105) you need to consider.
 

Output
For each n, output P(n) in a single line.
 

Sample Input
5
11 
15 
19
Sample Output
56 
176 
490

Source
 
 1 /**
 2 
 3 1  2   5   7   12   15  22  26
 4 **/
 5 
 6 #include<iostream>
 7 #include<stdio.h>
 8 #include<cstring>
 9 #include<cstdlib>
 using namespace std;
 typedef __int64 LL;
 const int maxn = 1e5+;
 LL  p = ;
 LL dp[maxn];
 LL five1[];
 LL five2[];
 void init()
 {
     int i,j,t;
     for(LL k=;k<=;k++)
         five1[k] = k*(*k-)/;
     for(LL k=;k<=;k++)
         five2[k] = k*(*k+)/;
 
     dp[]=;
     for(i=;i<maxn;i++)
     {
         dp[i] = ;
         j=;
         t=;
         while()
         {
             if(i - five1[t]>=)
             {
                 dp[i] =dp[i] + j*dp[i-five1[t]] ;
             }
             else break;
 
             dp[i] = (dp[i]%p+p)%p;
 
             if( i - five2[t]>=)
             {
                 dp[i] = dp[i] + j*dp[i-five2[t]] ;
             }
             else break;
 
             dp[i] = (dp[i]%p+p)%p;
 
             j = -j;
             t++;
         }
         dp[i] = (dp[i]%p+p)%p;
     }
 }
 int main()
 {
     int T,n;
     init();
     scanf("%d",&T);
     while(T--)
     {
         scanf("%d",&n);
         printf("%I64d\n",dp[n]);
     }
     return ;
 }

HDU 4651 Partition 整数划分,可重复情况的更多相关文章

  1. hdu 4651 Partition(整数拆分+五边形数)

    Partition Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. hdu 4651 Partition (利用五边形定理求解切割数)

    下面内容摘自维基百科: 五边形数定理[编辑] 五边形数定理是一个由欧拉发现的数学定理,描写叙述欧拉函数展开式的特性[1] [2].欧拉函数的展开式例如以下: 亦即 欧拉函数展开后,有些次方项被消去,仅 ...

  3. HDU 4651 Partition(整数拆分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){    f[0 ...

  4. hdu - 4651 - Partition

    题意:把一个整数N(1 <= N <= 100000)拆分不超过N的正整数相加,有多少种拆法. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...

  5. hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/detail ...

  6. hdu 4651 - Partition(五边形数定理)

    定理详见维基百科....http://zh.wikipedia.org/wiki/%E4%BA%94%E9%82%8A%E5%BD%A2%E6%95%B8%E5%AE%9A%E7%90%86 代码如下 ...

  7. HDU 4651 (生成函数)

    HDU 4651 Partition Problem : n的整数划分方案数.(n <= 100008) Solution : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题 ...

  8. HDU 5230 ZCC loves hacking 大数字的整数划分

    http://acm.hdu.edu.cn/showproblem.php?pid=5230 把题目简化后,就是求 1---n - 1这些数字中,将其进行整数划分,其中整数划分中不能有重复的数字,如果 ...

  9. HDU 1028 Ignatius and the Princess III dp整数划分

    http://acm.hdu.edu.cn/showproblem.php?pid=1028 dp[i][j]表示数值为i,然后最小拆分的那个数是j的时候的总和. 1 = 1 2 = 1 + 1 . ...

随机推荐

  1. codeforces 520 Pangram

    http://codeforces.com/problemset/problem/520/A A. Pangram time limit per test 2 seconds memory limit ...

  2. [原创]java WEB学习笔记65:Struts2 学习之路--Struts的CRUD操作( 查看 / 删除/ 添加) ModelDriven拦截器 paramter 拦截器

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  3. ofbiz进击 第六节。 --OFBiz配置之[widget.properties] 配置属性的分析

    配置内容分析如下 # -- 定义上下文使用者 -- security.context =default # -- 定义密码限制长度最小值 -- password.length.min =5 # -- ...

  4. linux env

    .Linux的变量种类 按变量的生存周期来划分,Linux变量可分为两类: 1.1 永久的:需要修改配置文件,变量永久生效. 1.2 临时的:使用export命令声明即可,变量在关闭shell时失效. ...

  5. sql set xact_abort on 用例

    set xact_abort on 设置事务回滚的当为ON时,如果你存储中的某个地方出了问题,整个事务中的语句都会回滚为OFF时,只回滚错误的地方 例子 : ALTER proc [dbo].[BuC ...

  6. Scrum站立会议----11月4日

    小组名称:nice! 组长:李权 成员:于淼  刘芳芳韩媛媛 宫丽君 时间:2016.11.4    12:00--12:30 地点:传媒西楼220室 代码地址:Https:  https://git ...

  7. 【crunch bang】字体美化

    中文字体美化是个很讨厌的事情,无数初学者在这里面浪费了无数时间,做了无数没有意义的事情.但这也是不得不做的,我把 Debian/Ubuntu 所需要的中文字体美化操作步骤详细记录在这里,希望能节约大家 ...

  8. Writable、WritableComparable和comparators

    hadoop的序列化格式 hadoop自身的序列化存储格式就是实现了Writable接口的类,他只实现了前面两点,压缩和快速.但是不容易扩展,也不跨语言. 我们先来看下Writable接口,Writa ...

  9. COM编程之二 接口

    [1]接口 DLL的接口是它所输出的那些函数. C++类的接口是该类的一个成员函数集. COM接口是包含一个函数指针数组的内存结构. 每一个数组元素包含的是一个由组件所实现的函数的地址. 在COM中接 ...

  10. Tomcat端口被占用快速解决方案

    在dos下,输入  netstat   -ano|findstr  8080 //说明:查看占用8080端口的进程 显示占用端口的进程 taskkill  /pid  6856  /f //说明,运行 ...