[hihoCoder] #1096 : Divided Product
描述
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的更多相关文章
- HOJ 1096 Divided Product (DFS)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given two positive integers N and M, please divide N into sev ...
- hiho1096_divided_product
题目 给出两个正整数N和M, N <= 100, M <= 50, 可以将N分解成若干个不相等的正整数A1, A2... Ak的和,且A1, A2 ... Ak的乘积为M的倍数.即 N = ...
- 【堆栈应用一】一个数divided=几个最小质因数的乘积
/******************************************堆栈:一个数divided几个质因数(质因数的乘积为N)***************************** ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- 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 ...
- 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 ...
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- hihoCoder #1072 辅导
题意 $\DeclareMathOperator{\lcm}{lcm}$选 $k$ ($k\le 10$) 个 $1$ 到 $n$($n\le 10^9$)之间的整数(可以相同),使得 $\lcm(a ...
- hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...
随机推荐
- 【Nodejs】理想论坛帖子爬虫1.02
在1.01版本中,我发现各回调函数找到数据后再插入数据库有个竞争问题不好解决,如果等所有回调都完成也没有好的处理方法,因为启动不止一处启动了新的TopicSpider实例. 于是我决定把读数据和写DB ...
- Opera Unite 用户指南
Opera Unite 用户指南 1 Opera Unite 简介 Opera Unite is a collaborative technology that allows you to share ...
- HDU 4620 Fruit Ninja Extreme 暴搜
题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...
- php之快速入门学习-9(switch)
PHP Switch 语句 switch 语句用于根据多个不同条件执行不同动作. PHP Switch 语句 如果您希望有选择地执行若干代码块之一,请使用 switch 语句. <?php sw ...
- gradle 添加jar依赖,执行grade build时出现“程序包不存在”问题
引用的第三方依赖的包都找不到了 解决办法 group'com.suneony' version'1.0.0' apply plugin:'java' repositories { mavenLocal ...
- AFN同步异步请求
异步请求: -(BOOL)getOnlyKey1 { NSString *myUUIDStr = [[[UIDevice currentDevice] identifierForVendor] UUI ...
- 转:Python 从FTP 下载数据的例子
<hadoop权威指南>的天气数据可以在ftp://ftp3.ncdc.noaa.gov/pub/data/noaa下载,在网上看到这个数据好开心,打开ftp发现个问题,呀呀,这么多文件啊 ...
- VB LISTBOX属性
additem 添加属性 listcount总记录数 listindex索引值 Private Sub Form_Load()List1.AddItem "广东省广州市"List1 ...
- asp.net MVC在IIS7或7.5上的发布问题
按照网上的做法,开启了ISAPI和CGI限制C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll 应用程序池也设置好了,可是就是 ...
- 使用任务Task 简化异步编程
使用任务简化异步编程 Igor Ostrovsky 下载代码示例 异步编程是实现与程序其余部分并发运行的较大开销操作的一组技术. 常出现异步编程的一个领域是有图形化 UI 的程序环境:当开销较大的操作 ...