题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658

题意:给出n、k。求n的拆分方案数。要求拆分中每个数不超过k。

i64 f[N];

void init()
{
    f[0]=f[1]=1; f[2]=2;
    int i,j,k,t;
    for(i=3;i<N;i++) for(j=1;;j++)
    {
        FOR0(k,2)
        {
            if(!k) t=(3*j*j-j)/2;
            else t=(3*j*j+j)/2;
            if(t>i) break;
            if(j&1) f[i]=(f[i]+f[i-t])%mod;
            else f[i]=(f[i]-f[i-t])%mod;
        }
        if(t>i) break;
    }
}

int n,m;

i64 cal()
{
    i64 ans=f[n];
    int i,j=-1,k;
    for(i=1;;i++,j=-j)
    {
        k=(3*i*i-i)/2*m;
        if(k>n) break;
        ans=(ans+f[n-k]*j)%mod;
        k=(3*i*i+i)/2*m;
        if(k>n) break;
        ans=(ans+f[n-k]*j)%mod;
    }
    if(ans<0) ans+=mod;
    return ans;
}

int main()
{
    init();
    rush()
    {
        RD(n,m);
        PR(cal());
    }
}

HDU 4658 Integer Partition(整数拆分)的更多相关文章

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

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

  2. HDU 4658 Integer Partition (2013多校6 1004题)

    Integer Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. hdu 4658 Integer Partition

    五角数定理!!可以参考这个http://www.cnblogs.com/xin-hua/p/3242428.html  代码如下: #include<iostream> #include& ...

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

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

  5. [LeetCode] Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  6. HDU-4651 Partition 整数拆分,递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:求n的整数拆为Σ i 的个数. 一般的递归做法,或者生成函数做法肯定会超时的... 然后要 ...

  7. 343 Integer Break 整数拆分

    给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积.例如,给定 n = 2,返回1(2 = 1 + 1):给定 n = 10,返回36(10 = 3 ...

  8. [LeetCode] 343. Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  9. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

随机推荐

  1. flashdevelop 开发技巧

    FlashDevelop用来编写AS3代码,Flash CS5用来编辑程序所需要的资源(图片,声音-),Flash CS5自带有Flex SDK,在目录 C:\Program Files\Adobe\ ...

  2. iOS-CALayer图片淡入淡出动画

    ]; } - (.f;          CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:, ,  ...

  3. POJ 2195

    #include<iostream>//by Chengdacaizi #include<stdio.h> #include<vector> #include< ...

  4. 概述Log4j简介

    在强调可重用组件开发的今天,除了自己从头到尾开发一个可重用的日志操作类外,Apache为我们提供了一个强有力的日志操作包-Log4j. Log4j是Apache的一个开放源代码项目,通过使用Log4j ...

  5. ios开发之AppDelegate

    创建应用程序之后之后,默认有AppDelegate.h文件与AppDelegate.m文件.   AppDelegate为何物?  AppDelegate为整个应用的一个代理,提供程序启动.退出等类似 ...

  6. js中的call与apply

    看js权威指南里面关于call与apply方法的说明:我们可以将call()与apply()看作是某个对象的方法,通过调用方法的形式来间接调用函数.这样的解释未免使人糊涂啊.下面说一下自己的见解:其实 ...

  7. ​浅谈Asp.net的sessionState

    见:http://my.oschina.net/kavensu/blog/330436

  8. SSH开发实践part3:hibernate继承映射

    0 大家好.上次讲了关于hibernate中双向1-N的映射配置,可以参考:http://www.cnblogs.com/souvenir/p/3784510.html 实际项目中,对象间的关系比较复 ...

  9. JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-004嵌套组件的注解AttributeOverrides

    一.数据库 二.代码 1. package org.jpwh.model.advanced; import javax.persistence.AttributeOverride; import ja ...

  10. J-link V8固件升级记

    http://blog.sina.com.cn/s/blog_5bdee3020101khfy.html 好久没为电子工程事业尽份力了!今天也稍微努把力!写写我是如何升级J-link的固件的吧! J- ...