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. 【Origin】时迁念昔

    -清明,未曾归,恰大门来沪,晨起准备,车道劳顿,隔五年而见一面,感时事变迁,物各两异,小道旁之争艳花木,觉道长且阻,叹而留记. 清明时节雨纷纷, 不辞跋涉见故人; 红花绿叶皆失色, 握手言欢语无伦. ...

  2. java反射机制简介

    1.字节码.所谓的字节码就是当java虚拟机加载某个类的对象时,首先需要将硬盘中该类的源代码编译成class文件的二进制代码(字节码),然后将class文件的字节码加载到内存中,之后再创建该类的对象 ...

  3. Android 发送短信与接收短信

    package com.example.testsms; import android.app.Activity; import android.app.PendingIntent; import a ...

  4. 动态LOV语句、向具有LOV的ITEM赋值时报FRM-40212需要验证错误

    网上解决方法: http://www.itpub.net/thread-845812-2-1.html http://blog.csdn.net/rfb0204421/article/details/ ...

  5. 夺命雷公狗—angularjs—21—解决angularjs压缩问题

    我们在实际的开发中往往离不开js的代码压缩,因为这样可以减轻服务器的压力,是的的方法如下所示: <!DOCTYPE html> <html lang="en" n ...

  6. PAT乙级 1009. 说反话 (20)

    1009. 说反话 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一句英语,要求你编写程序,将句中 ...

  7. 3. 星际争霸之php设计模式--简单工厂模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  8. windows下nginx和php环境的配置

    至于php的配置,与之前博文中使用apache服务器时一样. 对于nginx的配置,来看看如何修改配置文件: #user nobody; worker_processes ; #error_log l ...

  9. 【ruby】ruby基础知识

    Install Ruby(安装) For windows you can download Ruby from http://rubyforge.org/frs/?group_id=167 for L ...

  10. 不小心rm删除文件怎么办

    不小心rm删除文件怎么办 rm 命令的副作用越来越显现.而且rm掉之后的东西想找回来很困难.有2个原则: 1 永远不要在root下操作,尤其是rm命令 2 写一个别名,代替rm 我就是在~/.bash ...