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 ...
随机推荐
- Phyre LCUE with YEBIS cause issues about GS
when LCUE enabled in phyreEngine when Yebis integrated and render there are two mainloopdraws in one ...
- Mybatis 自动从数据库生成entity,mapping,dao接口
1.下载需要的jar包 mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.39.jar 2.把上面的jar包放到某个目录,并在该目录下 ...
- VSFTPD全攻略(/etc/vsftpd/vsftpd.conf文件详解)
/etc/vsftpd/vsftpd.conf文件详解,分好类,方便大家查找与学习 #################匿名权限控制############### anonymous_enable=YE ...
- javascript遍历子元素
最近写代码时需要获取符合某些条件的节点子元素,用firstChild之类的方法会包含文本节点,所以包装了一个简单的类: //子元素遍历器 function ElementWalker(node) { ...
- VS Bug 当获取其他项目的代码时, F5 无法进入调试模式. 也不报错....
在64位的机子下, 被获用的项目使用X86时会出现. 就会出现 F5 无法进入调试模式. 也不报错.... 打断点也没有用. 在不加入X86项目的代码时, 又可以运行.. 解决方案: 检查 ...
- 用HAProxy和KeepAlived构建高可用的反向代理
用HAProxy和KeepAlived构建高可用的反向代理 用HAProxy和KeepAlived构建高可用的反向代理 前言对于访问量较大的网站来说,随着流量的增加单台服务器已经无法处理所有的请求 ...
- EditorWindow edit ScriptableObject
using UnityEngine; [System.Serializable] public class Weapon { //[SerializeField] public string weap ...
- CentOS 6下安装nginx
原文:http://yubosun.akhtm.com/tech/centos-nginx.htm 1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/dow ...
- MFC单文档程序结构
MFC单文档程序结构三方面: Doc MainFrame View
- 在Delphi中实现动画窗口
Windows下有一个函数AnimateWindow,在Delphi自带的Win32 API Help中是找不到的.你可以在Delphi的编辑器中输入windows.等待代码向导出来,继续输入Anim ...