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 ...
随机推荐
- 查看xcode的路径
sudo /usr/libexec/locate.updatedb locate liblaunch_sim
- [学习笔记]设计模式之Proxy
为方便读者,本文已添加至索引: 设计模式 学习笔记索引 写在前面 “魔镜啊魔镜,谁是这个世界上最美丽的人?” 每到晚上,女王都会问魔镜相同的问题(见Decorator模式).这是她还曾身为女巫时留下的 ...
- 引入的iframe是跨域的, 如何控制其高度
前提是你有编辑这个跨域的iframe的权限!! 1. main-domain.html (main display HTML) <!DOCTYPE html> <html> & ...
- 使用gdb跟踪Linux内核启动过程(从start_kernel到init进程启动)
本次实验过程如下: 1. 运行MenuOS系统 在实验楼的虚拟机环境里,打击打开shell,使用下面的命令 cd LinuxKernel/ qemu -kernel linux-/arch/x86/b ...
- (三)跟我一起玩Linux网络服务:DHCP服务配置之主服务器配置
我们今天来做DHCP服务器的配置,我们的前提示要实现用一台虚拟机做DHCP服务器 1.首先,我们要有DHCP软件,我们用到下面两个软件(可以使用其他方法从网上直接安装,具体方法网络搜索) dhcp-3 ...
- 为什么我们需要使用 touch 命令
为什么我们需要使用 touch 命令 既然 touch 命令描述的是改变时间戳,那么我们可能会想为什么我们需要去改变时间戳呢?这个问题会引发我们的深思.然而,我想有个理由可以解释为什么我们需要使用它. ...
- PHP页面静态化入门
<?php /** *PHP页面静态化分为以下步骤: *1.打开输出控制缓存 *2.返回输出缓存区的内容 *3.将一个字符串写入文件 *4.冲刷出缓存区的内容 */ //1.打开输出控制缓存 o ...
- 使用jQuery播放/暂停 HTML5视频
文章来自:http://blog.okbase.net/jquery2000/archive/4485.html 我尝试用jQuery控制HTML5视频,两个视频分别在两个tab中,我希望点中tab后 ...
- python基础 [Alex视频]
vi hello.py#!/usr/bin/env pythonprint "hello world!"while True: print("hello world!&q ...
- Android Audio 分析
一.架构 二.MediaServer初始化 所有的media服务都在进程mediaserver里.其代码在framework/base/media/mediaserver/main_mediaserv ...