poj3252Round Numbers
也算是组合 以前按组合做过一次 忘记怎么做的了
这次按dp写的 dp[i][j][g][k] 表示第i位为k(0|1)而且有j个1,g个0的情况数
貌似写的麻烦了。。。这一类的题,进行逐位计算就可以 不过要很细心,边界处理 特殊情况处理什么的 。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[][][][];
int d[];
void init()
{
int i,j;
dp[][][][] = ;
dp[][][][] = ;
for(i = ; i <= ; i++)
for(j = ; j <= i ; j++)
{
int k = i-j;
dp[i][j][k][] += dp[i-][j][k-][]+dp[i-][j][k-][];
dp[i][j][k][] += dp[i-][j-][k][]+dp[i-][j-][k][];
} }
int judge(int x,int f)
{
int g=,i,j,e;
while(x)
{
d[++g] = x%;
x/=;
} int ans=;
for(j = ; j < g; j++)
for(i = ; i <= j ;i++)
{
int k = j-i; if(k>=i)
ans+=dp[j][i][k][];
}
int o = ;
for(i = g- ; i >= ; i--)
{
if(d[i+]) o--;
else o++;
if(!d[i]) continue;
if(i==)
{
o++;
if(o>=) ans++;
continue;
}
for(e = ; e <= i ; e++)
{
int k = i-e;
if(k-e+o>=)
ans+=dp[i][e][k][];
}
}
if(f)
{
o = ;
for(i = ; i<= g ;i++)
if(d[i]) o--;
else o++;
if(o>=) ans++;
}
return ans;
}
int main()
{
int a,b;
init();
while(cin>>a>>b)
{
cout<<judge(b,)-judge(a,)<<endl;
}
return ;
}
poj3252Round Numbers的更多相关文章
- poj3252Round Numbers【组合数】【数位dp】
Round Numbers The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, ...
- POJ3252-Round Numbers 数学
题目链接:http://poj.org/problem?id=3252 题目大意: 输入两个十进制正整数a和b,求闭区间 [a ,b] 内有多少个Round number 所谓的Round Numbe ...
- POJ3252Round Numbers(数位dp)
题意 给出区间$[A, B]$,求出区间内的数转成二进制后$0$比$1$多的数的个数 $1 \leqslant A, B \leqslant 2,000,000,000$ Sol 比较zz的数位dp ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- 20170223 遇到自建表里面相同key值数据不唯一
我怎么发现这个表里 key值相同数据不唯一, 这两条看起来是完全相同的, 其实排序不能能合并已经说明问题.
- ABAP debug遇到问题
新项目的系统,调试是老出现这个框不断弹出,一堆出来 都来不及关. 不确定是不是因为可用对话框不够的原因.
- install build tools 25.0.2 and sync the project
install build tools 25.0.2 and sync the project in android studio bundle.gradle,将buildToolsVersion修改 ...
- redis08----集群
集群的作用: .主从备份,防止主机宕机 .读写分离,主服务器写,从服务器内容跟着主服务器,主服务器变他就变,读就从从服务器读.减轻主服务器的负担. .任务分离,比如消耗cpu和内存的操作,交给从服务器 ...
- React在Render中使用bind可能导致的问题
因为bind在render的时候会重现生成,这样会导致props每次都不同, puremixin的插件也会失效. 所以需要将bind的结果缓存下来,或者直接在constructor里做这个事情 con ...
- 牛客练习赛42 E.热爆了
这可能是全场最长的一份代码 问的其实是对于关键点的斯坦纳树大小 考虑补集转化,不合法的点就是它的子树中没有关键点的点和斯坦纳树根的祖先 树根不难求,关键点中dfs序最大最小点的LCA就是了 问题在前者 ...
- HDU1358 Period —— KMP 最小循环节
题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- WinDbg 查看静态变量
有如下Class.若想查看静态变量内容.因为静态变量和类绑定,仅需要查看类即可. namespace ConsoleApplication13 { class Program { public sta ...
- trying to draw too large(106,975,232 bytes) bitmap.
Loading Large Bitmaps Efficiently This lesson teaches you to Read Bitmap Dimensions and Type Load a ...
- Bootstrap-CL:按钮组
ylbtech-Bootstrap-CL:按钮组 1.返回顶部 1. Bootstrap 按钮组 按钮组允许多个按钮被堆叠在同一行上.当你想要把按钮对齐在一起时,这就显得非常有用.您可以通过 Boot ...