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. (转) Java读取文本文件中文乱码问题

    http://blog.csdn.net/greenqingqingws/article/details/7395213 最近遇到一个问题,Java读取文本文件(例如csv文件.txt文件等),遇到中 ...

  2. 转:python webdriver API 之层级定位

    在实际的项目测试中,经常会有这样的需求:页面上有很多个属性基本相同的元素 ,现在需要具体定位到其中的一个.由于属性基本相当,所以在定位的时候会有些麻烦,这时候就需要用到层级定位.先定位父元素,然后再通 ...

  3. c++之路进阶——bzoj3343(教主的魔法)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser  gryz2016 Logout 捐赠本站 Notice:由于本OJ ...

  4. 通过反射封装JDBC

    具体上代码我的BaseDao: public class BaseDao<T> {  private Class clazz;  private Properties pro=null;  ...

  5. 从C#的Singleton设计模式

    近来,我在学习如何在C#语言中使用设计模式中读到一些资料,其中有关Singleton设计模式引起了我的注意. 学过设计模式的开发者都知道Singleton模式.我想简要地解释一下这个设计模式是为那些尚 ...

  6. 【ubuntu】install openbox+tint2+bmenu on ubuntu12.04.4

    原文地址: http://ndever.net/articles/linux/install-openbox-ubuntu-1304-1310 openbox是我用过的轻量窗口中最好用的了. Step ...

  7. OpenStack 镜像密码修改办法

    Contents [hide] 1 场景 2 方案一 3 方案二 4 方案三 5 目前采用方案三 场景 用户将实例里的root密码修改了,/root/.ssh/的公钥文件删除了,然后把密码忘记了,需要 ...

  8. android 应用架构随笔一(架构搭建)

    1.拷贝积累utils以及PagerTab类 2.定义BaseApplication类 3.定义BaseActivity类 4.改写MainActivity 5.定义布局文件 6.定义BaseFrag ...

  9. 鸟哥的linux私房菜学习记录之认识系统服务(daemons)

  10. 161102、MyBatis中批量插入

    方法一: <insert id="insertbatch" parameterType="java.util.List"> <selectKe ...