Problem Description
There are no days and nights on byte island, so the residents here can hardly determine the length of a single day. Fortunately, they have invented a clock with several pointers. They have N pointers which can move round the clock. Every pointer ticks once
per second, and the i-th pointer move to the starting position after i times of ticks. The wise of the byte island decide to define a day as the time interval between the initial time and the first time when all the pointers moves to the position exactly the
same as the initial time.

The wise of the island decide to choose some of the N pointers to make the length of the day greater or equal to M. They want to know how many different ways there are to make it possible.
 

Input
There are a lot of test cases. The first line of input contains exactly one integer, indicating the number of test cases.

  For each test cases, there are only one line contains two integers N and M, indicating the number of pointers and the lower bound for seconds of a day M. (1 <= N <= 40, 1 <= M <= 263-1)
 

Output
For each test case, output a single integer denoting the number of ways.
 

Sample Input

3
5 5
10 1
10 128
 

Sample Output

Case #1: 22
Case #2: 1023
Case #3: 586
 
题意:给你n个数,这n个数的大小为1~n,让你从中挑出一些数,使得这些数的最小公倍数大于等于m,求挑选的方案数。
思路:因为数的最小公倍数很大,所以不好dp,但是我们打表可以发现不同最小公倍数的总数量不是很大,所以我们用map<ll,ll>dp[50]来表示前i个数中挑选出的数的最小公倍数的值为j的方案数。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define inf 99999999
#define pi acos(-1.0)
ll gcd(ll a,ll b){
return (b>0)?gcd(b,a%b):a;
} ll cal(ll x,ll y)
{
ll num;
num=gcd(x,y);
return x*y/num; }
map<ll,ll>dp[50];
map<ll,ll>::iterator it; void init()
{
int i,j;
for(i=1;i<=40;i++)dp[i].clear();
dp[1][1]=1;
for(i=2;i<=40;i++){
for(it=dp[i-1].begin();it!=dp[i-1].end();it++){
dp[i][it->first]+=it->second;
dp[i][cal(it->first,i) ]+=it->second;
}
dp[i][i]+=1;
}
} int main()
{
int i,j,T,cas=0;;
ll n,m;
init();
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
ll sum=0;
for(it=dp[n].lower_bound(m);it!=dp[n].end();it++){
if(it->first>=m)
sum+=(it->second);
}
cas++;
printf("Case #%d: %lld\n",cas,sum);
}
return 0;
}

hdu4028 The time of a day (map+dp)的更多相关文章

  1. Codeforces 960 二进制构造子序列 完全二叉树shift模拟 主席树/MAP DP

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  2. hdu4028 The time of a day[map优化dp]

    The time of a day Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others ...

  3. [C++ map & dp]codeforces 960F. Pathwalks

    题目传送门:960F 思路: 题目给人的感觉很像最长上升子序列,自然而然想到用dp的思路去处理 题目中给的限制条件是,要接上前面的边,前面的边权一定要小于当前的边权(题目按照输入的顺序,因此只找前面的 ...

  4. 状态压缩dp入门

    poj1321 http://poj.org/problem?id=1321 我们可以把棋盘的每一行看做是一个状态,如果某一列放置了棋子,那么就标记为1,否则就标记为0.然后把它看成是一个二进制数,然 ...

  5. dp练习(3)——棋盘问题

    设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马. 规定: 1)马只能走日字 2)马只能向右跳 问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2, ...

  6. SPOJ - AMR11A(DP)

    Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did ...

  7. DP动态规划练习

    先来看一下经典的背包问题吧 http://www.cnblogs.com/Kalix/p/7617856.html  01背包问题 https://www.cnblogs.com/Kalix/p/76 ...

  8. codeforces的dp专题

    1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...

  9. 刷题总结——bzoj1725(状压dp)

    题目: 题目描述 Farmer John 新买了一块长方形的牧场,这块牧场被划分成 N 行 M 列(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地. FJ  ...

随机推荐

  1. ubuntu 安装 docker 并配置镜像加速(使用 apt-get 进行安装)

    ubuntu 安装docker CentOS docker安装 https://blog.csdn.net/weixin_44953227/article/details/108597310 你需要这 ...

  2. linux网关服务器

    问题 多台服务器在内网网段,其中只有一台有公网ip可以上外网,需要让所有服务器都能连接外网 解决思路 使用路由转发的方式,将拥有公网ip的服务器搭建为网关服务器,即作为统一的公网出口 所谓转发即当主机 ...

  3. ps的参数解释

    [root@bogon ~]# ps axuUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND user启动进程的用户 pid  表示进程标志 ...

  4. 【Linux】NFS搭建及使用详解

    环境:CentOS release 6.8 server  192.168.25.100 client1 192.168.25.101 client2 192.168.25.102 1.服务端操作 1 ...

  5. 【Python】在CentOS6.8中安装pip9.0.1和setuptools33.1

    wget https://bootstrap.pypa.io/ez_setup.py python ez_setup.py install --如果这个文件安装需要下载的文件无法下载的话,手动下载,放 ...

  6. scp等不需要存入know_host

    1.修改sshd的配置文件 vi /etc/ssh/ssh_config 修改为如下 StrictHostKeyChecking no UserKnownHostsFile /dev/null 重启s ...

  7. Flask扩展点总结(信号)

    信号(源码) 信号,是在flask框架中为我们预留的钩子,让我们可以进行一些自定义操作. pip3 install blinker 根据flask项目的请求流程来进行设置扩展点 1.中间件 from ...

  8. 免安装的tomcat转服务

    一:确保tomcat 在点击bin\startup 文件可以正常启动访问: 二:本机安装有JDK: 三:本机环境变量配置:JAVA_HOME:C:\Java\jdk1.7.0_17; 四:本机Tomc ...

  9. 使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理

    使用Linux服务器来通过网络安装和激活Windows 7 -- 一些基本原理 https://www.pufengdu.org/blog/?p=372

  10. jasper使用table组件设计复杂的表头

    1.1 设计报表模板 1.1.1 新建模板DemoReport5.jrxml,去掉不需要的Band,保留Title,Page Header,Detail 1 , PageFooter.将组件Table ...