hdu4028 The time of a day (map+dp)
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.
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)
5 5
10 1
10 128
Case #2: 1023
Case #3: 586
#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)的更多相关文章
- 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 ...
- 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 ...
- [C++ map & dp]codeforces 960F. Pathwalks
题目传送门:960F 思路: 题目给人的感觉很像最长上升子序列,自然而然想到用dp的思路去处理 题目中给的限制条件是,要接上前面的边,前面的边权一定要小于当前的边权(题目按照输入的顺序,因此只找前面的 ...
- 状态压缩dp入门
poj1321 http://poj.org/problem?id=1321 我们可以把棋盘的每一行看做是一个状态,如果某一列放置了棋子,那么就标记为1,否则就标记为0.然后把它看成是一个二进制数,然 ...
- dp练习(3)——棋盘问题
设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马. 规定: 1)马只能走日字 2)马只能向右跳 问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2, ...
- SPOJ - AMR11A(DP)
Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did ...
- DP动态规划练习
先来看一下经典的背包问题吧 http://www.cnblogs.com/Kalix/p/7617856.html 01背包问题 https://www.cnblogs.com/Kalix/p/76 ...
- codeforces的dp专题
1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...
- 刷题总结——bzoj1725(状压dp)
题目: 题目描述 Farmer John 新买了一块长方形的牧场,这块牧场被划分成 N 行 M 列(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地. FJ ...
随机推荐
- ubuntu 安装 docker 并配置镜像加速(使用 apt-get 进行安装)
ubuntu 安装docker CentOS docker安装 https://blog.csdn.net/weixin_44953227/article/details/108597310 你需要这 ...
- linux网关服务器
问题 多台服务器在内网网段,其中只有一台有公网ip可以上外网,需要让所有服务器都能连接外网 解决思路 使用路由转发的方式,将拥有公网ip的服务器搭建为网关服务器,即作为统一的公网出口 所谓转发即当主机 ...
- ps的参数解释
[root@bogon ~]# ps axuUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND user启动进程的用户 pid 表示进程标志 ...
- 【Linux】NFS搭建及使用详解
环境:CentOS release 6.8 server 192.168.25.100 client1 192.168.25.101 client2 192.168.25.102 1.服务端操作 1 ...
- 【Python】在CentOS6.8中安装pip9.0.1和setuptools33.1
wget https://bootstrap.pypa.io/ez_setup.py python ez_setup.py install --如果这个文件安装需要下载的文件无法下载的话,手动下载,放 ...
- scp等不需要存入know_host
1.修改sshd的配置文件 vi /etc/ssh/ssh_config 修改为如下 StrictHostKeyChecking no UserKnownHostsFile /dev/null 重启s ...
- Flask扩展点总结(信号)
信号(源码) 信号,是在flask框架中为我们预留的钩子,让我们可以进行一些自定义操作. pip3 install blinker 根据flask项目的请求流程来进行设置扩展点 1.中间件 from ...
- 免安装的tomcat转服务
一:确保tomcat 在点击bin\startup 文件可以正常启动访问: 二:本机安装有JDK: 三:本机环境变量配置:JAVA_HOME:C:\Java\jdk1.7.0_17; 四:本机Tomc ...
- 使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理
使用Linux服务器来通过网络安装和激活Windows 7 -- 一些基本原理 https://www.pufengdu.org/blog/?p=372
- jasper使用table组件设计复杂的表头
1.1 设计报表模板 1.1.1 新建模板DemoReport5.jrxml,去掉不需要的Band,保留Title,Page Header,Detail 1 , PageFooter.将组件Table ...