hdu 4028 2011上海赛区网络赛H dp+map离散
一开始用搜索直接超时,看题解会的
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#define inf 110000
#define M 10005
#define N 10005
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define pb(a) push_back(a)
#define mem(a,b) memset(a,b,sizeof(a))
#define eps 1e-9
#define zero(a) fabs(a)<eps
#define LL long long
#define MOD 1000000007
using namespace std;
map<LL,LL>dp[];
map<LL,LL>::iterator it;
LL gcd(LL a,LL b){
return b==?a:gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
void DP(){
dp[][]=;
for(int i=;i<=;i++){
dp[i]=dp[i-]; //不取第i个数的所有情况,先复制过来
dp[i][i]++; //只取第i个数,不能落下
for(it=dp[i-].begin();it!=dp[i-].end();it++)
dp[i][lcm(i,it->first)]+=it->second; //然后考虑在前i-1个数的基础上加入第i个数
}
}
LL n,m;
int main(){
DP();
int t,cas=;
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d",&n,&m);
LL ans=;
//遍历一遍
for(it=dp[n].begin();it!=dp[n].end();it++)
if(it->first>=m)
ans+=it->second;
printf("Case #%d: %I64d\n",++cas,ans);
}
return ;
}
hdu 4028 2011上海赛区网络赛H dp+map离散的更多相关文章
- hdu 4026 2011上海赛区网络赛F TSP ****
没看过TSP,先mark //4838039 2011-10-27 23:04:15 Accepted 4026 2343MS 31044K 3143 B C++ Geners //状态压缩DP的TS ...
- hdu 4038 2011成都赛区网络赛H 贪心 ***
贪心策略 1.使负数为偶数个,然后负数就不用管了 2.0变为1 3.1变为2 4.2变为3 5.若此时操作数剩1,则3+1,否则填个1+1,然后回到5
- hdu 4025 2011上海赛区网络赛E 压缩 ***
直接T了,居然可以这么剪枝 题解链接:点我 #include<cstdio> #include<map> #include<cstring> #define ll ...
- hdu 4023 2011上海赛区网络赛C 贪心+模拟
以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 #include<cstdio> #include<iostream> #include<algori ...
- hdu 4027 2011上海赛区网络赛G 线段树 成段平方根 ***
不能直接使用成段增减的那种,因为一段和的平方根不等于平方根的和,直接记录是否为1,是1就不需要更新了 #include<cstdio> #include<iostream> # ...
- hdu 4035 2011成都赛区网络赛E 概率dp ****
太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...
- hdu 4044 2011北京赛区网络赛E 树形dp ****
专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...
- hdu 4036 2011成都赛区网络赛F 模拟 **
为了确保能到达终点,我们需要满足下面两个条件 1.能够到达所有山顶 2.能够在遇到苦土豆时速度大于他 二者的速度可以用能量守恒定律做,苦土豆的坐标可通过三角形相似性来做 #include<cst ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
随机推荐
- 怎样将myeclipse里默认编码设置成utf-8
需要设置三个位置: [1]需要在 Preferences->general->content types->下角是文件编码,可以自己定义 [2]windows->Prefer ...
- Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that ...
- SpringMVC中Controller跳转到另一个Controller方法
1.直接Redirect后加 Controller/Action Response.Redirect("/User/Edit"); return Redirect("/U ...
- Java for LeetCode 205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- a byte of python(摘02)
a byte of python 第四章 运算符与表达式 运算符 运算符优先级 (运算符通常由左向右结合,即具有相同优先级的运算符按照从左向右的顺序计算.例如, 2 + 3 + 4 被计算成 (2 + ...
- HDU 3111 Sudoku(精确覆盖)
数独问题,输入谜题,输出解 既然都把重复覆盖的给写成模板了,就顺便把精确覆盖的模板也写好看点吧...赤裸裸的精确覆盖啊~~~水一水~~~然后继续去搞有点难度的题了... #include <cs ...
- JavaScript实现字符串的contains函数
JavaScript实现字符串的contains函数 / * * string:原始字符串 * substr:子字符串 * isIgnoreCase:忽略大小写 * / function co ...
- OKhttp的封装(上)
自从介绍了OKhttp3的一些基本使用之后,又偷了下懒,所以它的续篇被搁置了一段时间,现在补充. OKhttpManager.Class 请求工具类 package com.example.admi ...
- Android仿快递 物流时间轴 的代码实现
首先,这篇参考了别人的代码.根据自己的项目需求简单改造了一下,效果图如下 xml:代码 <?xml version="1.0" encoding="utf-8&qu ...
- HDU 4946 Area of Mushroom (几何凸包)
题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...