hdu4427Math Magic
dp[i][j][k] i为K位的最小公倍数 j为k位的和 k以滚动数组的形式
这题最棒的是 有一个强有力的剪枝 组成公倍数m的肯定都是M的质因子 这样1000里面最多就30多个 复杂度可过了
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<queue>
using namespace std;
#define mod 1000000007
int dp[][][];
int q[][],f[],lc[][];
int p[];
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int n,m,k,i,j,g;
for(i = ; i <= ; i++)
for(j = ; j <= ; j++)
lc[i][j] = i*j/gcd(i,j);
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
int o;
int to = ;
for(i =; i <= m ; i++)
if(m%i==)
{
to++;
p[to] = i;
}
memset(dp,,sizeof(dp));
for(i = ; i <= min(n,m) ; i++)
{
dp[i][i][] = ;
}
for(i = ; i <= k; i++)
{
for(o = ; o <= to ; o++)
for(g = ; g <= n ; g++)
dp[p[o]][g][i%] = ;
for(j = ; j <= to ; j++)
{
for(g = i-; g <= n ; g++)
{
if(dp[p[j]][g][(i-)%]==)
continue;
for(o = ; o <= to ; o++)
{
int x = lc[p[j]][p[o]];
if(g+p[o]>n)
break;
if(x>m)
continue;
dp[x][g+p[o]][i%] = (dp[x][g+p[o]][i%]+dp[p[j]][g][(i-)%])%mod;
}
}
}
}
printf("%d\n",dp[m][n][k%]);
}
return ;
}
hdu4427Math Magic的更多相关文章
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- [8.3] Magic Index
A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted ar ...
- Python魔术方法-Magic Method
介绍 在Python中,所有以"__"双下划线包起来的方法,都统称为"Magic Method",例如类的初始化方法 __init__ ,Python中所有的魔 ...
- 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律
F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- 一个快速double转int的方法(利用magic number)
代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
- Magic xpa 2.5发布 Magic xpa 2.5 Release Notes
Magic xpa 2.5發佈 Magic xpa 2.5 Release Notes Magic xpa 2.5 Release NotesNew Features, Feature Enhance ...
- How Spring Boot Autoconfiguration Magic Works--转
原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...
随机推荐
- 9 I/O复用
I/O复用使得程序能够同时监听多个文件描述符,适用于以下情况: 客户端同时处理多个socket,比如非阻塞connect 客户端同时处理用户输入和网络连接,比如聊天室程序 TCP服务器同时处理监听so ...
- [Bug]没有对“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files”的写访问权限
问题 环境WIN8.1 x64,新安装的vs与iis,在部署网站时,出现该异常信息.本地机作为测试机,就部署一个站点进行测试,没想到出现这个错误. 解决方案 如果你访问上面的那个路径,你会发现并没有那 ...
- Web流程
Web阻塞加载,异步加载. 延迟执行,立即执行. 加载并执行,不要调用代码. 加载并执行时会调用代码,但是加载并执行时不要调用代码,否则会改变逻辑. 上面是Web流程,JS只是web的一部分.如果关注 ...
- CSS自定义文件上传按钮
今天一同事问我文件上传按钮的问题,情况是这样的,他页面上有3个按钮,分为左中右三个,左边的位按钮甲,右边的位按钮乙,而中间的就是个文件选择按钮,情况大概是这个样子的: 两边的按钮都有了样式,但中间的选 ...
- iOS-OpenGLES 简单渲染
UIImage *showImage = [UIImage imageNamed:, , showImage.size.width, showImage.size.height); ) fo ...
- 评论 “App死亡潮:400万应用僵尸超八成,周期仅10月”
点这里 原文: App死亡潮:400万应用僵尸超八成,周期仅10月 时间 2015-04-05 22:48:19 和讯科技相似文章 (16)原文 http://tech.hexun.com/201 ...
- NoSQL数据库有哪些
NoSQL太火,冒出太多产品了,保守估计也成百上千了. 互联网公司常用的基本集中在以下几种,每种只举一个比较常见或者应用比较成功的例子吧. 1. In-Memory KV Store : Redis ...
- nodejs上传图片并显示的例子
目标 1. 在浏览器地址栏输入“http://demos/start”,进入欢迎页面,页面有一个文件上传表单: 2. 选择一张图片并提交表单,文件被上传到"http://demos/uplo ...
- SMB2 Protocol – 简介(应用层协议主要用于在计算机间共享文件、打印机、串口等)
SMB2 Protocol – 简介 SMB协议简介: 服务器信息块(SMB)协议是一个应用层协议主要用于在计算机间共享文件.打印机.串口等. 在介绍SMB协议的时候,一般提到使用的端口为139,44 ...
- QT静态编译
Qt静态编译(链接)和动态编译区别 Qt的静态编译译(其实应该叫链接,不是编译),将各模块编译成静态库,这样在编译自己写的Qt程序时,会将这些静态库编译(链接)到你的EXE文件中去的.Qt的动态编译, ...