hdu 4658 Integer Partition
五角数定理!!可以参考这个http://www.cnblogs.com/xin-hua/p/3242428.html
代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 100001
using namespace std;
const int mod=;
int an[MAX],n,t,k;
void init(){
int i,j;
an[]=an[]=;
an[]=;an[]=;an[]=;
an[]=;
for(i=;i<MAX;i++){
an[i]=;
for(j=;;j++){
int g=j*(*j-)/;
if(i-g<) break;
if(j&) an[i]+=an[i-g];
else an[i]-=an[i-g];
an[i]=an[i]%mod;
while(an[i]<) an[i]+=mod;
g=j*(*j+)/;
if(i-g<) break;
if(j&) an[i]+=an[i-g];
else an[i]-=an[i-g];
an[i]=an[i]%mod;
while(an[i]<) an[i]+=mod;
}
an[i]%=mod;
}
}
int solve()
{
int ans=an[n];
for(int j=;;j++){
int g=k*j*(*j-)/;
if(n-g<) break;
if(j&) ans-=an[n-g];
else ans+=an[n-g];
ans=ans%mod;
while(ans<) ans+=mod;
g=k*j*(*j+)/;
if(n-g<) break;
if(j&) ans-=an[n-g];
else ans+=an[n-g];
ans=ans%mod;
while(ans<) ans+=mod;
}
return ans%mod;
}
int main(){
init();
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
printf("%d\n",solve());
}
return ;
}
hdu 4658 Integer Partition的更多相关文章
- hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/detail ...
- HDU 4658 Integer Partition (2013多校6 1004题)
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4658 Integer Partition(整数拆分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:给出n.k.求n的拆分方案数.要求拆分中每个数不超过k. i64 f[N]; void i ...
- 【hdu 4658】Integer Partition (无序分拆数、五边形数定理)
hdu 4658 Integer Partition 题意 n分拆成若干个正整数的和,每个正整数出现小于k次,分拆方案有多少.(t<=100,n<=1e5) 题解 之前写过一篇Partit ...
- Integer Partition(hdu4658)2013 Multi-University Training Contest 6 整数拆分二
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 1047 Integer Inquiry
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...
- HDU 3208 Integer’s Power
Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1047 Integer Inquiry(高精度数)
Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hi ...
随机推荐
- OC6_复合类的类存管理
// // Person.h // OC6_复合类的类存管理 // // Created by zhangxueming on 15/6/18. // Copyright (c) 2015年 zhan ...
- 关于HTML与CSS编写规范
之前一直没有注意到这一点,因为当看到一些优秀的网站的源代码的时候,打开他们引用的css文件格式看起来也并非规范.但幸运的昨天偶然间看到的通过增强CSS规范可读性可优化页面性能,于是下决心痛改前非. 我 ...
- thinkphp3.2引入php 实例化类
如果你的类库没有采用命名空间的话,需要使用import方法先加载类库文件,然后再进行实例化,例如:我们定义了一个Counter类(位于Com/Sina/Util/Counter.class.php): ...
- Java Web容器的启动与处理请求的过程
容器启动时的加载顺序 一.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<context-param>结点.二.容创建一个ServletContext(ser ...
- stl::find,find_if,find_if_not
//满足特定条件下的实现,回调函数template<class InputIt, class UnaryPredicate> InputIt find_if(InputIt first, ...
- IE6下window.location.href不跳转到相应url
前天一同事遇到个看似很诡异的问题,就是<a href="javascript:void(0);" onclick="window.location.href=url ...
- 让Dock自动 显示/隐藏 不再有延迟
Safari 5.2 Mac OS X 10.7.2 <ignore_js_op> 可能很多朋友使用Mac的时候都会选择将Dock隐藏(可以在系统偏好设置-Dock中选择),等到使用的时候 ...
- CSS 中的 em单位
em的对应的像素值如何计算,一言以蔽之:em就是倍数当前元素font-size的倍数,其结果就是当前字体的像素值乘以em的值,至于font-size来自何处?有两个来源:继承自父元素和通过CSS直接设 ...
- PHP获取IP及地区信息(纯真IP数据库)
昨天在写程序的时候,发现在用户的时候记录IP和地区信息也许以后用得上,去网上找了找,发现实现的方式有好多好多,因为我用的ThinkPHP,后来又去TP官网找了找,最后采用了下面这种方法. <?p ...
- 转 在无法通过yum下载非标准包时,怎么办
在CentOS下,我们可以通过yum来下载或更新rpm包,但是标准的源(repository)里只提供一部分的rpm包,虽然大部分情况下,这些包是够用的.但是有时候还是需要下载其他的一些非标准的包,如 ...