整数划分问题--DFS
单点时限: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.
例子输入
7 2
例子输出
4
例子提示
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.
思路就是暴力 , 把全部情况都试一下.
#include <iostream>
using namespace std;
typedef unsigned long long ull;
ull N, M;
ull r = 0;
const ull MOD = 1000000007;
void dfs (ull i, ull s, ull p) {
if (s == N) {
if (p % M == 0) r++;
return;
}
for (ull j = i + 1; j < N - s + 1; j++) {
dfs (j, s + j, p * j);
}
}
int main () {
cin >> N >> M;
dfs (0, 0, 1);
cout << r % MOD << endl;
return 0;
}
整数划分问题--DFS的更多相关文章
- 整数划分问题-解法汇总(暂有DP-递归)
整数划分问题是一个锻炼组合数学,递归以及动态规划很好的例子,虽然问题看似简单,但是其中玄机万千,有人转化成为背包问题,有人用生成函数解,有人以此作为企业面试题目,可见这种问题的认可度还是很高的. 整数 ...
- noi 7219:复杂的整数划分问题
7219:复杂的整数划分问题 查看 提交 统计 提问 总时间限制: 200ms 内存限制: 65536kB 描述 将正整数n 表示成一系列正整数之和,n=n1+n2+…+nk, 其中n1>= ...
- hdu1028(整数划分问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分问题 整数划分 --- 一个老生长谈的问题: 描述 整数划分是一个经典的问题.请写一个程 ...
- noi7219 复杂的整数划分问题
noi7219 复杂的整数划分问题 #include <bits/stdc++.h> using namespace std; ; int dp1[maxn][maxn], dp2[max ...
- POJ 2429 GCD & LCM Inverse (Pollard rho整数分解+dfs枚举)
题意:给出a和b的gcd和lcm,让你求a和b.按升序输出a和b.若有多组满足条件的a和b,那么输出a+b最小的.思路:lcm=a*b/gcd lcm/gcd=a/gcd*b/gcd 可知a/gc ...
- Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS
进入a b 多少努力p, q 使p*q == a && p < q && p >= b 直接大整数分解 然后dfs所有可能的解决方案劫持 #include ...
- 华为OJ平台——放苹果(典型整数划分问题)
题目描述: 输入m,n,分别表示苹果数与盘子的总数,要求输出苹果放在n个盘子的方法总数(注意511和151是一种情况),例如输入 7 3 输出8((7),(6,1),(5,2),(4,3),(5,1, ...
- poj 3181 Dollar Dayz (整数划分问题---递归+DP)
题目:http://poj.org/problem?id=3181 思路:将整数N划分为一系列正整数之和,最大不超过K.称为整数N的K划分. 递归:直接看代码: 动态规划:dp[i][j]:=将整数i ...
- 区间dp 整数划分问题
整数划分(四) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 暑假来了,hrdv 又要留学校在参加ACM集训了,集训的生活非常Happy(ps:你懂得),可是他最近 ...
随机推荐
- ARC 067 E - Grouping
题面在这里! 很显然是个暴力dp. 我们先枚举一下 队伍人数的种类,然后再逆序枚举一下dp数组里的总人数(顺序就会算重),最后枚举一下这种队伍的数量,之后就可以O(1)算方案了. 具体的,O(1)算方 ...
- HDU 5137 How Many Maos Does the Guanxi Worth 最短路 dijkstra
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- Mac OSX系统下通过ProxyChains-NG实现终端下的代理
项目主页:https://github.com/rofl0r/proxychains-ng 官方说明: proxychains ng (new generation) - a preloader wh ...
- STLink download/debug interface for Linux.
http://arm-utilities.googlecode.com/svn-history/r47/trunk/stlink-download/stlink-download.c /* STLin ...
- java 盒子模型
http://www.cnblogs.com/xiaohuochai/tag/javascript%E6%80%BB%E7%BB%93/
- Delphi7下使用FastMM4
1> 将文件Replacement BorlndMM DLL/Precompiled/for Delphi IDE/Performance/BorlndMM.dll,替换掉Delphi/Bin下 ...
- win8.1快速启动选项突然消失了怎么办?
win8开始提供的快速启动功能是一种混合式的休眠模式,Windows系统 在关机时将系统的信息保存到硬盘上的一个文件中来实现下一次的快速启动.当再次启动电脑时, Windows 使用该系统信息文件来恢 ...
- Latex Error cannot determine the size of graphic 报错的解决的方法
Latex Error cannot determine the size of graphic 报错的解决的方法 插入jpg文件老是会报错... 追究了半天,原来是编译的命令又问题,不应该使用 la ...
- MVC路由之浅见
1.定义路由.路由规则 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{re ...
- python文本 maketrans和translate
python文本 maketrans和translate 场景: 过滤字符串的某些字符,我们从例子出发 >>> tb=str.maketrans ('abc','123') & ...