4427

dp[i][j][k] i为K位的最小公倍数 j为k位的和 k以滚动数组的形式

这题最棒的是 有一个强有力的剪枝 组成公倍数m的肯定都是M的质因子 这样1000里面最多就30多个 复杂度可过了

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<queue>
  7. using namespace std;
  8. #define mod 1000000007
  9. int dp[][][];
  10. int q[][],f[],lc[][];
  11. int p[];
  12. int gcd(int a,int b)
  13. {
  14. return b==?a:gcd(b,a%b);
  15. }
  16. int main()
  17. {
  18. int n,m,k,i,j,g;
  19. for(i = ; i <= ; i++)
  20. for(j = ; j <= ; j++)
  21. lc[i][j] = i*j/gcd(i,j);
  22. while(scanf("%d%d%d",&n,&m,&k)!=EOF)
  23. {
  24. int o;
  25. int to = ;
  26. for(i =; i <= m ; i++)
  27. if(m%i==)
  28. {
  29. to++;
  30. p[to] = i;
  31. }
  32. memset(dp,,sizeof(dp));
  33. for(i = ; i <= min(n,m) ; i++)
  34. {
  35. dp[i][i][] = ;
  36. }
  37. for(i = ; i <= k; i++)
  38. {
  39. for(o = ; o <= to ; o++)
  40. for(g = ; g <= n ; g++)
  41. dp[p[o]][g][i%] = ;
  42. for(j = ; j <= to ; j++)
  43. {
  44. for(g = i-; g <= n ; g++)
  45. {
  46. if(dp[p[j]][g][(i-)%]==)
  47. continue;
  48. for(o = ; o <= to ; o++)
  49. {
  50. int x = lc[p[j]][p[o]];
  51. if(g+p[o]>n)
  52. break;
  53. if(x>m)
  54. continue;
  55. dp[x][g+p[o]][i%] = (dp[x][g+p[o]][i%]+dp[p[j]][g][(i-)%])%mod;
  56. }
  57. }
  58. }
  59. }
  60. printf("%d\n",dp[m][n][k%]);
  61. }
  62. return ;
  63. }

hdu4427Math Magic的更多相关文章

  1. 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 ...

  2. [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 ...

  3. Python魔术方法-Magic Method

    介绍 在Python中,所有以"__"双下划线包起来的方法,都统称为"Magic Method",例如类的初始化方法 __init__ ,Python中所有的魔 ...

  4. 【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 ...

  5. 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 ...

  6. 一个快速double转int的方法(利用magic number)

    代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...

  7. MAGIC XPA最新版本Magic xpa 2.4c Release Notes

    New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...

  8. 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 ...

  9. How Spring Boot Autoconfiguration Magic Works--转

    原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...

随机推荐

  1. Phyre LCUE with YEBIS cause issues about GS

    when LCUE enabled in phyreEngine when Yebis integrated and render there are two mainloopdraws in one ...

  2. Mybatis 自动从数据库生成entity,mapping,dao接口

    1.下载需要的jar包 mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.39.jar 2.把上面的jar包放到某个目录,并在该目录下 ...

  3. VSFTPD全攻略(/etc/vsftpd/vsftpd.conf文件详解)

    /etc/vsftpd/vsftpd.conf文件详解,分好类,方便大家查找与学习 #################匿名权限控制############### anonymous_enable=YE ...

  4. javascript遍历子元素

    最近写代码时需要获取符合某些条件的节点子元素,用firstChild之类的方法会包含文本节点,所以包装了一个简单的类: //子元素遍历器 function ElementWalker(node) { ...

  5. VS Bug 当获取其他项目的代码时, F5 无法进入调试模式. 也不报错....

    在64位的机子下, 被获用的项目使用X86时会出现. 就会出现   F5 无法进入调试模式. 也不报错.... 打断点也没有用. 在不加入X86项目的代码时, 又可以运行..   解决方案:   检查 ...

  6. 用HAProxy和KeepAlived构建高可用的反向代理

      用HAProxy和KeepAlived构建高可用的反向代理 用HAProxy和KeepAlived构建高可用的反向代理 前言对于访问量较大的网站来说,随着流量的增加单台服务器已经无法处理所有的请求 ...

  7. EditorWindow edit ScriptableObject

    using UnityEngine; [System.Serializable] public class Weapon { //[SerializeField] public string weap ...

  8. CentOS 6下安装nginx

    原文:http://yubosun.akhtm.com/tech/centos-nginx.htm 1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/dow ...

  9. MFC单文档程序结构

    MFC单文档程序结构三方面: Doc MainFrame View

  10. 在Delphi中实现动画窗口

    Windows下有一个函数AnimateWindow,在Delphi自带的Win32 API Help中是找不到的.你可以在Delphi的编辑器中输入windows.等待代码向导出来,继续输入Anim ...