自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(40)
  • 收藏
  • 关注

原创 HDU-5713-K个联通块 状压dp 计数技巧 去重技巧

题意 给一张无重边(可能有自环),求有多少种方案使得删除一些边后有KK个连通块。题解 删边等于添边。设dp[s][i]dp[s][i]表示状态为s的子集有k个连通块的方案数,则有dp[S0][i]=∑dp[S2][i−1]∗dp[S1][1]dp[S_0][i] = \sum dp[S_2][i-1] * dp[S_1][1],s1s_1表示s0s_0的包含最后一个1的子集,s2s_2是s1

2016-06-01 21:17:44 652

原创 Codeforces problem 671C Ultimate Weirdness of an Array - 线段树

题意 定义F(l,r)F(l, r) 的值表示序列A[1:n]A[1:n] 的子序列A[1...(l−1),(r+1)...n]A[1...(l-1),(r+1)...n] 之中任意两个数的最大公约数的最大值。题解 If we calculate an array H where Hi is how many (l - r)s there are that f(l,  r)  ≤  i, t

2016-05-19 11:43:10 438

原创 KTU Programming Camp (Day 3) A. Queries - 线段树

题意 给出nn个数a1,a2,...,ana_1,a_2, ... , a_n和qq个操作 1 p x1\ p\ x 将a_p修改为x2 a b2\ a\ b求∑Elf(i,j)  (a<=i<=j<=b)\sum Elf(i,j)\ \ (a <= i <= j <= b),Elf(i,j)Elf(i, j)表示ai xor ai+1 xor ,..., xor aja_i\ xor\ a

2016-05-11 19:56:50 754

原创 Codeforces-665E-Beautiful Subarrays Trie树(字典树)

题意 给一个序列,这个序列有n个数,再给一个数k,定义Beautiful Subarrays为一个子序列的异或和大于等于k,求这个序列一共有多少个Beautiful Subarrays。题解 首先求出前缀异或和pre[i]=a[i] xor pre[i−1]pre[i] = a[i]\ xor\ pre[i-1] 区间[l,r][l, r] 的异或和就可以表示为pre[l] xor pre[r

2016-05-04 21:10:57 287

原创 KTU Programming Camp (Day 2) Problem F. Sequence of words 后缀数组+线段树

题意 题目链接给一个字符串S,给q个询问,每个询问包含L和K,求原字符串长度为L的字串中字典序排在第K位的起始位置。题解 首先处理出sa数组,然后将询问离线,按照L从大到小的顺序访问,将rnk[0]...rnk[n−L]rnk[0]...rnk[n-L]加入线段树中,查询排在第k位的rnk值,利用sa即可查到起始位置。代码#include <iostream>#include <cst

2016-04-27 21:14:27 427

原创 KTU Programming Camp (Day 2) Problem I. Lazy mobile users - 树形dp

题意 题目链接给一个有n个点的树,从1出发,每个点最多访问k次,求最多可以访问多少个点。题解 设 F(u)F(u) 为在满足每个点最多访问k次的条件下,从u这点出发并回到u点可以访问点数的最大值,G(u)G(u) 同样的条件下,从u这点出发但不返回u的最大值。F(u)=∑F(v)F(u)=\sum F(v) v表示u的孩子中最大的k−1k-1 个。G(u)=G(i)+∑F(v)G(u)

2016-04-27 17:23:52 644

原创 lightoj - 1299 - Fantasy Cricket - dp

lightoj - 1299 - Fantasy Cricket - dp题意 给出一个包含’U’, ‘D’, ‘E’的字符串,’U’ 表示需要把这个字符向后移动,’D’表示需要把这个字符向前移动,’E’表示这个字符不移动,求出移动后共有多少种情况。题解 设 dp[i][j]dp[i][j] 表示到第i个字符时,有j个U没放下。易知E对结果没影响。当 s[i]=Us[i] = U 时,

2016-04-21 11:01:37 594

原创 题目记录

cf631e 单调队列优化dp(三分)代码cf651e 并查集缩点 拓扑排序代码cf625e set贪心模拟代码cf629e lca 树形dp代码

2016-04-07 23:41:52 457

原创 hdu - 4281 - Judges' response - dp / 01背包 / mTSP

题意:给n个点,每个的费用为c[i],坐标为x[i], y[i]。背包容量为m。走在路上的速度为1.#include //#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define ll long long#define SZ(x) ((int)(x).size()) #de

2016-03-30 18:00:34 246

原创 lightoj - 1169 - Monkeys on Twin Tower - dp

题意:有两座塔,有n层,每层有一个水果,吃掉水果的时间分别时a[i], b[i],从i到i + 1层有两种方式,一种是直接上去,不消耗时间,另一种是跳到另一座塔,消耗u[i]或v[i]的时间。要跳到最高层,求最小时间。题解:每层有两种决策。#include //#pragma comment(linker, "/STACK:1024000000,1024000000")using n

2016-03-29 09:20:19 240

原创 lightoj - 1064 - Throwing Dice - dp / 概率dp

题意:有n个骰子,求他们的和至少为x的概率。题解:用dp统计所有情况,设dp[i][j]为到第i个骰子时,和为j的情况有多少种,则转移为dp[i][j] = sum(dp[i][j-k]),注意边界。而扔n个骰子共有6^n种情况,所以概率为sum(dp[n-1][j], j大于等于x) / 6^n 。#include //#pragma comment(linker, "/STA

2016-03-27 13:23:06 215

原创 lightoj - 1027 - A Dangerous Maze - dp / 概率dp

题意:给n个门,正数表示xi分钟后出去,负数表示-xi分钟后回到原地,选每个门的概率相等,求出去的时间的期望。题解:设

2016-03-26 22:41:24 170

原创 lightoj - 1193 - Dice (II) dp / 背包

题意:有n个骰子,每个骰子有k面,每个面的权值从1到k,求所有骰子和为s时,他们权值乘积的和。题解:设dp[i][j]表示到第i个骰子时和为j的乘积和,易写出dp[i][j] = sum{dp[i][j - m] * m, m从1到k,但是这样的dp方程是n * k * s的,所以要优化。类似完全背包的优化,写出dp[i][j-1]的方程,两式做差,得dp[i][j] = dp[i][j-1]

2016-03-26 21:25:07 226

原创 lightoj - 1033 - Generating Palindromes - dp/ 最长公共子序列lcs

题意:给一个串,可以在任意位置增加字符,求增加最少的字符使得原串成为回文串。题解:可以将原串倒置,求两串LCS,需要注意当j != n - i的特殊情况。#include //#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define ll long long#define

2016-03-26 16:00:38 199

原创 lightoj - 1105 - Fi Binary Number - 数位dp

题意:Fi-binary number是二进制位中没有两个相邻的1的数,例如1, 10, 100, 101. 求第n个Fi-binary number。题解:数位dp,可以参考画树形图的思考方式。#include //#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#de

2016-03-24 22:28:38 197

原创 lightoj - 1032 - Fast Bit Calculations - 数位dp

题意:将一个十进制数转化为二进制后,统计这一位是1,且下一位也是1的位数为这个数的权值,例如,6的二进制为110,第一1的下一位也是1,所以6的权值为1。给一个十进制数n,求0到n所有的十进制数的权值和。题解:数位dp,可以参考算法合集之《浅谈数位类统计问题》,用树形图来理解就容易多了。#include //#pragma comment(linker, "/STACK:1024

2016-03-24 20:24:55 205

原创 lightoj - 1036 - A Refining Company / dp

题意:给两张n*m的表格,第一张表格表示Uranium矿的位置,第二张表格表示Radium矿的位置,在表格的最上边是R矿的精炼厂,在表格的最左边是U矿的精炼厂,有两种传送带,一种从右到左,另一种从下到上,表格的一个格子内只能存在一种传送带,如果一个格子内的矿想要被传送带运输,那么这个格子内必须有传送带。传送带必须是直线才能运输,即从右到左的传送带只能运输U矿,从下到上的传送带只能运输R矿,要求修建

2016-03-23 17:37:29 330

原创 lightoj-1122 - Digit Count dp

1122 - Digit Count   PDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBGiven a set of digits S, and an integer n, you have to find h

2016-03-23 15:53:46 923

原创 lightoj-1381 - Scientific Experiment dp

John wants to be a scientist. A first step of becoming a scientist is to perform experiment. John has decided to experiment with eggs. He wants to compare the hardness of eggs from different species.

2016-03-23 13:11:32 394

原创 lightoj-1223-Testing Mailboxes 区间dp

1223 - Testing Mailboxes   PDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBWhen monkeys are given some fire-crackers, they have on

2016-03-22 22:14:32 501

原创 hihocoder-1274-高维dp

#1274 : 自行车架时间限制:5000ms单点时限:1000ms内存限制:256MB描述小Hi的宿舍楼下有一块用于停自行车的区域。平时自行车都停得非常杂乱,于是楼长打算去买一排自行车架用来停车。自行车架一般有P个槽,每个槽的两侧都可以停入自行车;但是一个槽位同时只能有一侧停入自行车。此外,停入一辆自行车会导致无法在这一侧的附近若干个槽

2016-03-21 23:50:36 545

原创 vimrc

set guifont=Monaco:h16set background=lightset shortmess=atIset cindent autoindent number sts=4 sw=4 ts=4 etset nobackupfiletype onfiletype plugin onfiletype indent onautocmd FileType pytho

2016-03-18 16:03:18 164

原创 Codeforces Round #333(div1.b/div2.d) / problem 601b - 单调栈

B. Lipshitz Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA function  is called Lipschitz conti

2015-11-26 08:41:10 249

原创 hdu-5569-matrix-dp

matrixTime Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 437    Accepted Submission(s): 260Problem DescriptionGiven a matrix with n

2015-11-25 19:59:18 198

原创 hdu-5568-sequence2-dp

sequence2Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 522    Accepted Submission(s): 189Problem DescriptionGiven an integer a

2015-11-25 19:34:06 219

原创 BestCoder补完计划

啃难题。BestCoder #63:hdu5568:

2015-11-25 19:32:40 149

原创 Codeforces Round #327 & problem - 590C - C. Three States - BFS

C. Three Statestime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe famous global economic crisis is approa

2015-10-26 11:58:20 283

原创 51nod-阶乘分数-阶乘数质因数分解/组合计数

1189 阶乘分数题目来源: Spoj基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注1/N! = 1/X + 1/Y,给出N,求满足条件的整数解的数量。例如:N = 2,1/2 = 1/3 + 1/6,1/2 = 1/4 + 1/4。由于数量可能很大,输出Mod 10^9 + 7。

2015-09-22 11:49:49 401

原创 codeforces-549F-Yura and Developers

F. Yura and Developerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYura has a team of k developers and a

2015-09-06 02:40:06 572

原创 codeforces round #160(div 1) b/ problem261b Maxim and Restaurant 概率/期望/组合数学/dp

B. Maxim and Restauranttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaxim has opened his own restaurant

2015-08-29 22:32:11 102

原创 poj-3783-Balls dp/线性dp

BallsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 792 Accepted: 513DescriptionThe classic Two Glass Balls brain-teaser is often posed as: "Give

2015-07-31 20:43:25 429

转载 hdu-2089-不要62 数位dp

hdu-2089不要62Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 23952    Accepted Submission(s): 8200Problem Description杭州人称那些傻乎乎粘

2015-07-29 12:42:47 222

转载 hdu-2089-不要62-数位dp

hdu-2089不要62Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 23952    Accepted Submission(s): 8200Problem Description杭州人称那些傻乎乎粘

2015-07-29 12:40:40 43

原创 hdu-1421-搬寝室 线性dp

搬寝室Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20975    Accepted Submission(s): 7125Problem Description搬寝室是很累的,xhd深有体会.时间追述2

2015-07-27 19:16:04 226

原创 poj-3061-Subsequence 尺取法/双指针法

SubsequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9865 Accepted: 3983DescriptionA sequence of N positive integers (10 < N < 100 000), each of t

2015-07-27 10:45:42 214

原创 lightoj-1422-Halloween Costumes 区间dp

1422 - Halloween CostumesPDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBGappu has a very busy weekend ahead of him. Becau

2015-07-27 09:18:10 213

原创 poj-1839-Two 树形dp/树的直径

TwoTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 1260 Accepted: 629DescriptionThe city consists of intersections and streets that connect them. 

2015-07-25 18:04:53 284

原创 poj-1655-Balancing Act 树形dp/树的重心

Balancing ActTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10637 Accepted: 4418DescriptionConsider a tree T with N (1 <= N <= 20,000) nodes numbered 1

2015-07-25 14:19:29 282

原创 poj3342-Party at Hail-Bula 树形dp/树的最大独立集

Party at Hali-BulaTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 5683 Accepted: 2030DescriptionDear Contestant,I'm going to have a party at my vill

2015-07-25 13:09:32 201

原创 poj1651-Multiplication Puzzle-区间dp/矩阵链乘

Multiplication PuzzleTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7040 Accepted: 4329DescriptionThe multiplication puzzle is played with a row of car

2015-07-24 12:11:46 231

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除