核心是要想到只枚举最小公倍数的因子

因为转移过程中一单添加了不是最小公倍数的因子,那么结果必然不合法,虽然最终答案是对的,但是这样的答案根本用不上,反而时间复杂度大大增加

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#define endl "\n"
#define me(a,b) memset(a,b,sizeof(a))
const int mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=;
int lcm[maxn][maxn];
void prepear() {
for(int i=; i<=; i++)
for(int j=; j<=; j++)
lcm[i][j]=(i*j)/__gcd(i,j);
}
int n,m,k;
int dp[][maxn][maxn];
int factor[],tol;
int main() {
prepear();
while(cin>>n>>m>>k) {
tol=;
for(int i=; i<=m; i++)
if(m%i==)
factor[tol++]=i;
me(dp,);
dp[][][]=;
int dir=;
for(int i=; i<=k; i++) {
dir^=;
me(dp[dir],);
for(int j=i-; j<=n; j++) {
for(int l=; l<=m; l++) {
if(dp[dir^][j][l]!=) {
for(int eu=;eu<tol;eu++){
int v=factor[eu];
if(v+j>n) break;
int nlcm=lcm[l][v];
if(nlcm>m||m%nlcm) continue;
(dp[dir][v+j][nlcm]+=dp[dir^][j][l])%=mod;
}
}
}
}
}
cout<<dp[dir][n][m]<<endl;
}
}

Math Magic ZOJ - 3662的更多相关文章

  1. UVALive 6073 Math Magic

                                                  6073 Math MagicYesterday, my teacher taught us about m ...

  2. Math Magic(完全背包)

    Math Magic Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

  3. [ZOJ 3662] Math Magic (动态规划+状态压缩)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3662 之前写过这道题,结果被康神吐槽说代码写的挫. 的确,那时候 ...

  4. ZOJ3662:Math Magic(全然背包)

    Yesterday, my teacher taught us about math: +, -, *, /, GCD, LCM... As you know, LCM (Least common m ...

  5. ZOJ-3662 Math Magic 背包DP

    这题不错,可惜我还是太弱了,没想到qwq. 看了网上大佬题解之后写的,对比了一下代码,好像我写的还是挺简洁的(逃,只是吞行比较多). 因为直接用lcm的值做下标会超时,所以我们观察发现可以组成lcm为 ...

  6. DP(优化) UVALive 6073 Math Magic

    /************************************************ * Author :Running_Time * Created Time :2015/10/28 ...

  7. hdu 4427 Math Magic DP

    思路: dp[i][j][k]表示满足前i个数,和为j,lcm为k的数目. 设a为解的第i+1个数. 那么状态转移就为 dp[i+1][j+a][lcm(a,k)]+=dp[i][j][k]. 但是由 ...

  8. hdu 4427 Math Magic

    一个长了一张数学脸的dp!!dp[ i ][ s ][ t ] 表示第 i 个数,sum为 s ,lcm下标为 t 时的个数.显然,一个数的因子的lcm还是这个数的因子,所以我们的第三维用因子下标代替 ...

  9. zoj 3662 第37届ACM/ICPC长春赛区H题(DP)

    题目:给出K个数,使得这K个数的和为N,LCM为M,问有多少种 f[i][j][k]表示选i个数,总和为j,最小公倍数为k memery卡的比较紧,注意不要开太大,按照题目数据开 这种类型的dp也是第 ...

随机推荐

  1. MySQL8.0关系数据库基础教程(三)-select语句详解

    1 查询指定字段 在 employee 表找出所有员工的姓名.性别和电子邮箱. SELECT 表示查询,随后列出需要返回的字段,字段间逗号分隔 FROM 表示要从哪个表中进行查询 分号为语句结束符 这 ...

  2. Golang import具体使用

    使用gopath的时候,一般引用是从src下一层开始,比如src/github.com/…,引用github.com…,我的工程src/xxx.com/go-qb/…,引用xxx.com/go-qb/ ...

  3. 关于在osgearth 中 出现 arial.ttf : file not handled 的问题

    这是由于配置osg时 freetype 插件没有配置到位. 我个人的解决方法 打开CMAKE,点击advance,不勾选OSG_TEXT_USE_FONTCONFIG. 同时将freetype路径设置 ...

  4. HDU Ignatius and the Princess II 全排列下第K大数

    #include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include& ...

  5. PHP独立环境配置

    php 下载地址: http://windows.php.net/download/ Apache 下载地址: http://www.apachelounge.com/download/ mysql ...

  6. 珠峰-cookie相关的东西

    ####  md5 #### #####

  7. 修改centos7容器的时间和宿主机时间一致

    一.问题 centos7系统容器时间与宿主机系统时间不一致,就进去查看一番,发现时区和宿主机上的时间不一致,下面就来解决一下 二.现象 1.查看centos宿主机的时间 输入如下命令查看 # date ...

  8. NCE L4

    课文内容 重点单词详解 课文内容详解

  9. codewars--js--Number of trailing zeros of N!

    问题描述: Write a program that will calculate the number of trailing zeros in a factorial of a given num ...

  10. POJ 1753 Flip Game 暴力 深搜

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59468   Accepted: 24750 Descr ...