题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位都为1,那么称为一个相邻的点, 一个数可能有多个相邻的点.现在给你一个数n, 问从1到n中有多少相邻的点. 解题思路:由于n的范围,所以不能用循环做.对于输入的数n可以通过n,直接求得答案. 假设n的二进制数为111100101111000, 对于中间的两个数111100101111000, 对于中…
题目大意: 一个数字把他看成二进制数字,数字里又会一些相邻的1,问从0到n至间所有相邻1的总和是多少?   分解成2进制数字,然后数位DP就行了.   ========================================================================   #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #inclu…
求一段区间中,每个十进制数所对应的二进制数中连续的1的个数之和. 设dp[i][0]代表长度为i的二进制数,首位为0,所含有的连续的1的个数之和. dp[i][1]代表长度为i的二进制数,首位为1,所含有的连续的1的个数之和. a: d[i][1]=d[i-1][0]+d[i-1][1]+(1<<(i-2)); b: d[i][0]=d[i-1][0]+d[i-1][1]; 这里面有一个需要注意的地方是,假设有一个数字是111,那么它含有2个连续的1,具体体现在 方程上是分两次计算的,一个是a…
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表第i位为j,前面已有k个1的个数. /** @Date : 2016-12-17-13.51 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : */ #include<bits/…
数位dp,许多数位dp需要统计某种模式(子串)出现的数量,这种题通常需要在递归参数中加入高位已经出现过的模式的数量. #include <cstdio> #include <cstring> using namespace std; #define D(x) ; long long n; int f[MAX_DIGIT]; ][MAX_DIGIT]; int cnt; int to_digits(long long a) { ; ) { f[ret++] = a % ; a /=…
http://lightoj.com/volume_showproblem.php?problem=1282 #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #define IOS ios::sync_with_stdio(false) using name…
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true" or "false" respectively). And every decimal number has a binary representation which is actually a series of bits. If a bit of a number is 1 a…
免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一个字符串i 到jLCS为k的方案数 1068 - Investigation 数位dp 能被K整数且各位数字之和也能被K整除的数 dp[i][j][k] 到第i位每位数字之和的余数为j 当前数字余数为k 1079 - Just another Robbery 01背包 全部钱之和为背包体积 不被抓的…
Fast Bit Calculations LightOJ - 1032 题意:求0到n的所有数的二进制表示中,"11"的总数量.(如果有连续的n(n>2)个1,记(n-1)个"11") 方法:常规数位dp.ans[pos][ans][f][pre0],pos当前位置,ans当前答案,f前一位,pre0是否在前导0 记一下看到的奇怪的做法:http://www.cnblogs.com/WABoss/p/5127652.html 错误(本地):注意:按这种模板来…
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 然后插入字典树 记录每一个单词的数量 输入一个句子 每一个单词也排序之后查找 依据乘法原理 答案就是每一个单词的数量之积 #include <iostream> #include <cstring> #include <cstdio> #include <algori…