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 ...
随机推荐
- Centos6.5 install Python2.7 & django & mysql & apache
#! /bin/bash#su root#get python2.7wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz #ins ...
- JS 定時刷新父類頁面
function timeCount() { var url = "MAC.aspx"; parent.location.href = url; } function beginC ...
- Struts2多文件上传
第一步:首先创建一个多文件上传的页面 <html> <head> <meta http-equiv="Content-Type" content=&q ...
- asp.net mvc5 设置Area下的为启动页
只需修改App_Start文件夹下RouteConfig中RegisterRoutes方法 public static void RegisterRoutes(RouteCollection rout ...
- C#程序中:如何修改xml文件中的节点(数据)
要想在web等程序中实现动态的数据内容给新(如网页中的Flash),不会更新xml文件中的节点(数据)是远远不够的,今天在这里说一个简单的xml文件的更新,方法比较基础,很适合初学者看的,保证一看就懂 ...
- linux自定义开机启动服务
转 http://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html 手工创建服务 1.在/etc/rc.d/init.d目录下创建shel ...
- Python核心编程2第三章课后练习
1. 标识符.为什么Python 中不需要变量名和变量类型声明? Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程.每个变量在内存中创建,都包括变量的标识,名称和数据这些信息.每 ...
- iOS: 学习笔记, 添加一个带界面约束的控制器
1. 创建一个空iOS应用程序(Empty Application). 2. 添加加控制器类. 修改控制器类的viewDidLoad - (void)viewDidLoad { [super view ...
- Noah的学习笔记之Python篇:装饰器
Noah的学习笔记之Python篇: 1.装饰器 2.函数“可变长参数” 3.命令行解析 注:本文全原创,作者:Noah Zhang (http://www.cnblogs.com/noahzn/) ...
- HTML+JS版本的俄罗斯方块
<!doctype html><html><head></head><body> <div id="box" st ...