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. 【剑指 Offer】10-I.斐波那契数列

    题目描述 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项.斐波那契数列的定义如下: F(0) = 0,   F(1) = 1 F(N) = F(N - 1) + F(N - ...

  2. HTTP基础知识点小结

    什么是http协议? http,超文本传输协议是现在互联网应用最为广泛的协议,所有的www文件都必须遵循这个标准设计这个最初的目的是为了发布和接收HTML文件.http就是web通信的基础,就是为了能 ...

  3. Promethues 之 Thanos

    Promethues简介和原理 请看我之前写的 Prometheus简介,原理和安装 https://www.cnblogs.com/you-men/p/12839535.html 官方架构问题 官方 ...

  4. ctfhub技能树—sql注入—字符型注入

    打开靶机 查看页面信息 查询回显位 查询数据库名(查询所有数据库名:select group_concat(schema_name) from information_schema.schemata) ...

  5. C# url的编码解码,xml和json的序列化和反序列化

    参考中国慕课网dot net web编程应用程序实践 using System; using System.Collections.Generic; using System.IO; using Sy ...

  6. BAPI_PO_CHANGE

    这两天用BAPI更改采购订单,遇到了一些问题,最后调试解决了.记录如下吧.要修改的是采购订单的物料号和批次,在网上看到其它人写过关于 BAPI_PO_CHANGE的用法,但是具体问题还要具体分析啊. ...

  7. redis修改requirepass 参数 改密码

    1. 不重启redis如何配置密码? a. 在配置文件中配置requirepass的密码(当redis重启时密码依然有效). # requirepass foobared  ->  修改成 :  ...

  8. ElasticSearch-IK分词器和集成使用

    1.查询存在问题分析 在进行字符串查询时,我们发现去搜索"搜索服务器"和"钢索"都可以搜索到数据: 而在进行词条查询时,我们搜索"搜索"却没 ...

  9. 如果using语句中出现异常,资源会被释放掉吗?

    <CLR Via C#>第三版 P489 在using内部抛出了异常,被using的对象还是会被释放掉. Using编译时会自动生成Try Finally代码块. 同样Using只能用于实 ...

  10. vue2.0、vue3.0不同之处

    一.响应式赋值操作不同 Vue2.0 1.通过data返回对象做相应: 2.对复杂的对象或数组下的属性等深层次的改变需要通过$set的方式. Vue3.0 1.ref实现简单的实现响应,通过value ...