时间限制: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

题意:给一个数N,能分解成多少个数,这些数满足题目所说的4个条件。问有多少种情况?
思路:看到N最大只有100,1+2+3...+14>100最多14层递归。用DFS找出所有情况。
感想:1.其中有个乘法要注意下数据范围,第一用了int,WA了,后来改用long long。
2.题目数据貌似水了,这题要求GCD,目前还没看懂,先贴个水过的代码,以后再补上。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 500
int vis[maxn],a[maxn];
int n, m, cnt;
void dfs(int sum, long long mul, int pos, int num)
{
if(sum == n && mul%m ==)
{
// for(int i = 0; i < num; i++)
// printf("%d ", a[i]);
// printf("\n");
cnt++;
return;
} for(int i = pos; i <= n; i++)
{
if(sum + i > n)
break;
a[num] = i;
dfs(sum+i, mul*i, i+, num+);
}
}
int main()
{
scanf("%d%d", &n, &m);
cnt = ;
dfs(,,,);
printf("%d\n", cnt%);
return ;
}

HOJ 1096 Divided Product (DFS)的更多相关文章

  1. [hihoCoder] #1096 : Divided Product

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

  2. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  3. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  4. 黑白图像(DFS)

    输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图6-11所示的图形有3个八连块. 图6-11  拥有3 ...

  5. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  6. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  7. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  8. 【算法导论】图的深度优先搜索遍历(DFS)

    关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...

  9. 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现

    1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...

随机推荐

  1. day57:00:26:34

    今天开始用博客记录倒计时,也只是为了看看今天做了什么.这也是我第一用博客园记录考研生活了 倒计时57天,我在想每天花时间在这记录生活会不会浪费复习的时间,其实不会的了,不去看微博,少刷新闻....仔细 ...

  2. Java学习之Iterator(迭代器)的一般用法

    迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...

  3. JavaScript 数组的遍历

    var a = [1, 2, 3]; // for循环 for(var i = 0; i < a.length; i++) { console.log(a[i]); } // while循环 v ...

  4. PHP设计模式笔记五:策略模式 -- Rango韩老师 http://www.imooc.com/learn/236

    策略模式 1.概述:策略模式,将一组特定的行为和算法封装成类,以适应某些特定的上下文环境,这种模式称为策略模式 例如:一个电商网站系统,针对男性女性用户要各自跳转到不同的商品类目,并且所有广告位展示不 ...

  5. 【百度之星2014~初赛(第二轮)解题报告】Chess

    声明 笔者近期意外的发现 笔者的个人站点http://tiankonguse.com/ 的非常多文章被其他站点转载.可是转载时未声明文章来源或參考自 http://tiankonguse.com/ 站 ...

  6. 【计算机视觉】基于行为的ReID演示

    帮老师做了一个简单的基于行为(主要是步态)的ReID问题的Demo,效果例如以下图: 以下是提取的集中特征,前三个都是GEI系的,后几个是基于光流场的.然后右边是识别出的几个对象的排序,由于没有角度和 ...

  7. SegmentFault 巨献 1024 程序猿游戏「红岸的呼唤」第三天任务攻略

    第三关也不是一般的难呐,那么继续写一下解题过程(第四关会是什么样呢?). 高速传送门:http://segmentfault.com/game/3 在用我想到的方法(booth算法.矩阵变换.各种CP ...

  8. android Log.isLoggable步骤的使用

    原文地址: http://www.cnblogs.com/maxinliang/p/4024442.html android Log.isLoggable方法的使用 android 动态控制logca ...

  9. 华为 oj 水题 数字颠倒

    练手,献给初学者 #include <stdio.h> #include <string.h> int main(void) { char string[200]={'\0'} ...

  10. Small factorials Solved Problem code: FCTRL2

    import sys def fact(n): final = n while n > 1: final *= n - 1 n -= 1 return final #逻辑严谨,不要忘了retur ...