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. :“boost/serialization/string.hpp”: No such file or directory 错误

    主要原因是没有安装和配置boost库. 解决:http://www.programlife.net/boost-compile-and-config.html

  2. for穷举

    穷举:把所有可能的情况都走一遍,使用if条件筛选出来满足的条件的情况.(把所有的可能性都列举一边) 迭代:从初始情况按照规律不断求解中间情况,最终推导出结果.f foreach  专为数组定义的一种命 ...

  3. struts_19_对Action中所有方法、某一个方法进行输入校验(手工编写代码实现输入校验)

    对所有方法进行校验1.通过手工编写代码的形式实现 需求:用户名:不能为空手机号:不能为空,并且要符合手机号的格式1,3/5/8,后面是9个数字 第01步:导包 第02步:配置web.xml <? ...

  4. 在EditText前面添加一个搜索的小图片

    1,这是EditText中的一个小的属性 代码: android:drawableLeft="@drawable/searchico" 效果图如下:

  5. Struts2部署在Websphere上的问题

    配置Mapped Filter:可以解决Struts2的项目部署在WebSphere6.1下面,发生Action找不到的情况. 应用程序服务器>[选择所使用的服务器]>Web 容器设置&g ...

  6. [Ubuntu] Install subversion1.8 on Ubuntu13.10

    Subversion1.8 is difference far away from subversion1.7, here is the steps to install subversion1.8. ...

  7. web负载均衡

    在有些时候进行扩展是显而易见的,比如下载服务由于带宽不足而必须进行的扩展,但是,另一些时候,很多人一看到站点性能不尽如人意,就马上实施负载均衡等扩展手段,真的需要这样做吗?当然这个问题也只有他们自己能 ...

  8. selenium滚动条

    element = self.brower.find_element_by_id('xxx')brower.execute_script('arguments[0].scrollIntoView(); ...

  9. Ubuntu 安装 “宋体,微软雅黑,WPS Office的symbol、wingdings、wingdings 2、wingdings 3、webding字体,Consolas雅黑混合版编程字体” 等 Windows 7 下的字体(转)

    Windows平台下,"宋体"."微软雅黑"."Courier New(编程字体)"用的比较多,看的也习惯了.那如何在 Ubuntu下也安装 ...

  10. V4L2读取摄像头程序流程【转】

    本文转载自:https://my.oschina.net/u/1024767/blog/210801 v4l2 操作实际上就是 open() 设备, close() 设备,以及中间过程的 ioctl( ...