lightoj 1032 二进制的dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1032
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; long long dp[maxn];
int sum[] = {,,,,,,,,};
long long int N; inline long long res(int i){
return (<<i) + (<<(i-));
} int main()
{
freopen("E:\\acm\\input.txt","r",stdin);
dp[] = ;
for(int i=;i<=;i++){
dp[i] = *dp[i-] + (<<(i-));
}
int T;
cin>>T;
for(int cas=;cas<=T;cas++){
cin>>N;
printf("Case %d: ",cas);
if(N <= ){
printf("%d\n",sum[N]);
continue;
}
long long ans = ;
for(int i=;i>=;i--){
long long temp = <<i;
if(N >= temp){
ans += dp[i];
long long diff = N - res(i);
if(diff >= ){ //这个地方没有加等号WA了两次。
ans += diff + ;
}
N -= temp;
}
if(N == ) break;
}
cout<<ans+sum[N]<<endl;
}
}
lightoj 1032 二进制的dp的更多相关文章
- Fast Bit Calculations LightOJ - 1032
Fast Bit Calculations LightOJ - 1032 题意:求0到n的所有数的二进制表示中,"11"的总数量.(如果有连续的n(n>2)个1,记(n-1) ...
- bzoj3209 花神的数论题 (二进制数位dp)
二进制数位dp,就是把原本的数字转化成二进制而以,原来是10进制,现在是二进制来做,没有想像的那么难 不知到自己怎么相出来的...感觉,如果没有一个明确的思路,就算做出来了,也并不能锻炼自己的能力,因 ...
- LightOJ 1032 - Fast Bit Calculations 数位DP
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...
- lightoj 1032 - Fast Bit Calculations(数位dp)
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
- LightOJ - 1032 数位DP
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...
- 51nod 1413 权势二进制 背包dp
1413 权势二进制 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 一个十进制整数被叫做权势二进制,当他的十进制表示的时候只由0或1组成.例如0,1,101, ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- lightoj 1381 - Scientific Experiment dp
1381 - Scientific Experiment Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lightoj.com/vo ...
- BZOJ3329: Xorequ(二进制数位dp 矩阵快速幂)
题意 题目链接 Sol 挺套路的一道题 首先把式子移一下项 \(x \oplus 2x = 3x\) 有一件显然的事情:\(a \oplus b \leqslant c\) 又因为\(a \oplus ...
随机推荐
- shell脚本学习之Bash shell 里各种括号的用法
今天在 SegmentFault 上看到又有人问起关于Shell里各种括号的问题.对于很多玩Shell的人,括号是个很尴尬的问题,用起来没问题,说起来不明白,我在这里总结一下Bash Shell几种括 ...
- hdoj 2054(A==B)
注意考虑以下数据: 123 123.0; 0.123 .123; 00.123 0.123; 代码: #include<iostream>#include<cstdio> ...
- new、delete用法(一)
第一部分:new的使用: #define DEBUG_NEW new(THIS_FILE, __LINE__)解释 THIS_FILE:表示当前类所处的文件名: __LINE__:表示分配内存操作所在 ...
- SVM(支持向量机)算法
第一步.初步了解SVM 1.0.什么是支持向量机SVM 要明白什么是SVM,便得从分类说起. 分类作为数据挖掘领域中一项非常重要的任务,它的目的是学会一个分类函数或分类模型(或者叫做分类器),而支持向 ...
- [lua]尝试一种Case语法糖
function CaseT(arg) function proxy(caller) caller.yield(r) end -- proxy return function (cond) if (c ...
- sublime text 3 安装中文
本经验目前在Ubuntu14.04环境下,已有搜狗输入法 for Linux和Sublime Text 3的情况下安装成功. END 解决方法步骤2 1 保存下面的代码到文件sublime_imf ...
- fedora23开发环境搭建手册
chrome安装 [安装chrome教程] nodejs环境搭建 dnf install nodejs dnf install npm sublime text 编辑器安装配置 [fedora安装su ...
- Centos6.5安装
前奏:CentOS 6.5下载地址http://mirror.centos.org/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1to2.torre ...
- UI图标不用愁:矢量字体图标Font-Awesome
Font-Awesome,这个项目主要是css3的一个应用,准确的说是一段css,这里的把很多图标的东西做到了font文件里面,然后通过引用外部font文件的方式,来展现图标. Font Awesom ...
- quick-x 计时器的写法
local scheduler = require("framework.scheduler") --计时器 function MainScene:recoderTime() pr ...