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 ...
随机推荐
- html5--6-9 CSS选择器6--伪类选择器
html5--6-9 CSS选择器6--伪类选择器 实例 @charset="UTF-8"; /*:root{background: green}*/ /*li:first-chi ...
- os、sys和shutil模块
运行环境:python3 OS模块:os 模块提供了一个统一的操作系统的接口函数 下面的path指路径的意思 os.stat(file) #查询文件属性操作 os.sep #取代操作系统特定的路径分隔 ...
- Opencv:10个步骤检测出图片中条形码
1. 原图像大小调整,提高运算效率 2. 转化为灰度图 3. 高斯平滑滤波 4.求得水平和垂直方向灰度图像的梯度差,使用Sobel算子 5.均值滤波,消除高频噪声 6.二值化 7.闭运算,填充条形码间 ...
- iOS中NSNotification、delegate、KVO三者之间的区别与联系?
前面分别讲了delegate.notification和KVO的实现原理,以及实际使用步骤,我们心中不禁有个疑问,他们的功能比较类似,那么在实际的编程中,如何选择这些方式呢? 在网上看到一个博客上详细 ...
- 「LuoguP4047」 [JSOI2010]部落划分
Description 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成 ...
- 【Codeforces 582A】 GCD Table
[题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数. G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: ...
- vs 2015 community Blend和devenv启动的区别
使用Blend启动会有部分功能无法显示 如:SVN管理插件,工具栏 使用devenv启动会全部显示
- oracle 分库分表(sharding)
以下文章转载博客:http://blog.csdn.net/bluishglc 讲的很深入透彻,转来分享下: 数据库Sharding的基本思想和切分策 http://blog.csdn.net/blu ...
- centos7无故重启-内核升级
最近有一台物理服务器,centos7操作系统,无故重启,每天都会发生这种情况: 解决: 升级内核 CentOS 允许使用 ELRepo,这是一个第三方仓库,可以将内核升级到最新版本,使用ELRepo升 ...
- E20170403-gg
thumbnail 缩略图 inherit vt. 继承; vt. 经遗传获得(品质.身体特征等),继任; opacity 不透明度 flat adj. 平的; 单调的; 不景气的 ...