时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Given two positive integers N and M, please divide N into several integers A1, A2, ..., Ak (k >= 1), so that:

1. 0 < A1 < A2 < ... < Ak;

2. A1 + A2 + ... + Ak = N;

3. A1, A2, ..., Ak are different with each other;

4. The product of them P = A1 * A2 * ... * Ak is a multiple of M;

How many different ways can you achieve this goal?

输入

Two integers N and M. 1 <= N <= 100, 1 <= M <= 50.

输出

Output one integer -- the number of different ways to achieve this goal, module 1,000,000,007.

样例提示

There are 4 different ways to achieve this goal for the sample:

A1=1, A2=2, A3=4;

A1=1, A2=6;

A1=2, A2=5;

A1=3, A2=4.

样例输入
7 2
样例输出
4

说好的这题是动规呢?想了半天动规没想出来,写了个DFS,然后居然通过了。有空再想想。

 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std; typedef long long ll;
const ll MOD = ; int N, M; void dfs(ll &res, ll idx, ll sum, ll pro) {
if (sum == N) {
if (pro % M == ) ++res;
return;
}
for (int i = idx + ; i <= N - sum; ++i) {
dfs(res, i, sum + i, pro * i);
}
} void solve() {
ll res = ;
dfs(res, , , );
cout << res << endl;
} int main() {
while (cin >> N >> M) {
solve();
}
}

[hihoCoder] #1096 : Divided Product的更多相关文章

  1. HOJ 1096 Divided Product (DFS)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given two positive integers N and M, please divide N into sev ...

  2. hiho1096_divided_product

    题目 给出两个正整数N和M, N <= 100, M <= 50, 可以将N分解成若干个不相等的正整数A1, A2... Ak的和,且A1, A2 ... Ak的乘积为M的倍数.即 N = ...

  3. 【堆栈应用一】一个数divided=几个最小质因数的乘积

    /******************************************堆栈:一个数divided几个质因数(质因数的乘积为N)***************************** ...

  4. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  5. Optimizing Item Import Performance in Oracle Product Hub/Inventory

    APPLIES TO: Oracle Product Hub - Version 12.1.1 to 12.1.1 [Release 12.1] Oracle Inventory Management ...

  6. timer Compliant Controller project (1)--Product introduction meeting

    Last week ,I lead the meeting for new project. i'm  very excited. The meeting is divided into the fo ...

  7. PAT甲级——1096 Consecutive Factors (数学题)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors  ...

  8. hihoCoder #1072 辅导

    题意 $\DeclareMathOperator{\lcm}{lcm}$选 $k$ ($k\le 10$) 个 $1$ 到 $n$($n\le 10^9$)之间的整数(可以相同),使得 $\lcm(a ...

  9. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

随机推荐

  1. SqlServer 之 用 IP 地址连接数据库报错" 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误 "

    问题描述:       在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (p ...

  2. Hessian整合Spring

    含实例源码博客推荐:http://blog.csdn.net/julyness/article/details/49023581 简介: Hessian是一个简单的连接Web服务的二进制协议. 客户端 ...

  3. 亲自己主动手从源代码 构建 Groovy 2.3.8 公布包

    今天为了学习 怎样使用 Groovy 写 Groovy 的測试代码, 所以到 http://groovy.codehaus.org/Download 下载了 Groovy 2.3.8 的源码包. Gr ...

  4. rarcrack

    apt-get install rarcrack使用方法:rarcrack --threads xx --type rar xx.rar

  5. JQuery URL的GET参数值获取方法

    // jQuery url get parameters function [获取URL的GET参数值] // <code> // var GET = $.urlGet(); //获取UR ...

  6. HDU 5402 Travelling Salesman Problem(棋盘染色 构造 多校啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5402 Problem Description Teacher Mai is in a maze wit ...

  7. 科学计算法帮助类MathUtils

    import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; /** * 科学计算 ...

  8. spring mvc json的输入输出

    输入 前台代码: var cfg = { type: 'POST', data: JSON.stringify({userName:'winzip',password:'password',mobil ...

  9. java Socket Tcp示例三则(服务端处理数据、上传文件)

    示例一: package cn.itcast.net.p5.tcptest; import java.io.BufferedReader;import java.io.IOException;impo ...

  10. Job for vsftpd.service failed because the control process exited with error code

    # systemctl start vsftpd.serviceJob for vsftpd.service failed because the control process exited wit ...