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 ...
随机推荐
- window.showModalDialog的传值和返回值
window.showModalDialog(URL,dialogArgments,features) 打开一个新窗口 URL为要将打开的网页地址. dialogArgments为设定好传递给新视窗网 ...
- Understanding Convolution in Deep Learning
Understanding Convolution in Deep Learning Convolution is probably the most important concept in dee ...
- dojo简单添加一个Panel到父容器中
this.contentPane = new ContentPane(); this.set("content", this.contentPane.domNode); this. ...
- 修改MySQL数据库的密码
通过MySQL命令行,可以修改MySQL数据库的密码,下面就为您详细介绍该MySQL命令行,如果您感兴趣的话,不妨一看. 格式:mysql -u用户名 -p旧密码 password 新密码 1.给ro ...
- POJ 3484
Showstopper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1060 Accepted: 303 Descri ...
- jvm 之 国际酒店 6月25日上线内存溢出原因
6月25日OMS,Ihotel上线成功后执行了一个批处理,SOA报警提示某一台IHOTEL机器调用OMS失败率大于阀值,登录这个机器后发现这台机器CPU使用率处于80%以上,调用OMS有的时候超过5秒 ...
- Windows SEH学习 x86
windows 提供的异常处理机制实际上只是一个简单的框架.我们通常所用的异常处理(比如 C++ 的 throw.try.catch)都是编译器在系统提供的异常处理机制上进行加工了的增强版本.这里先抛 ...
- 关于vmware下复制linux系统虚拟机后eth0变成eth1问题解决
在vmware虚拟机中,当我们克隆或者复制linux系统虚拟机后,再启动系统时会发现系统下不再有eth0,而变成了eth1 当我们使用/etc/init.d/network restart重启网络时, ...
- oracle基础知识和常见问题
第一步新建数据库.名称:suning用户名:sys和system密码:lsw123456在cmd启动监听的命令 lsnrctl start如果无法启动 lsnrctl start原因可能是liste ...
- android学习--radiogroup学习
这个阶段在学习android的相关基本UI现将相关练习的代码粘贴在此便于后期学习之用(radio控件) 效果图: main_layout.xml <?xml version="1. ...