题目链接:http://codeforces.com/contest/811/problem/C 题意:给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都要出现在这个区间. 每个区间的价值为该区间不同的数的异或值,现在问你这n个数最大的价值是多少. 题解:一般这种说法的题目都是用dp的,然后显然设dp[i]表示前i个能取得的最大价值,然后再存一下每个数的起始位置和 结束位置然后n*n就可以了,具体看一下代码,挺短的. #include <iostream> #include…
C. Vladik and Memorable Trip   time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you…
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…
题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子,我们需要在2*n*m步之内走到终点,问怎样走才行(多解输出任意一个即可).我们一开始的位子是(1,1),终点位子是“F”,‘*’表示不能走的位子,游戏开始的时候,有一些小伙伴比较调皮,会将U和D互换,就是说假设我们操作了U,但是实际是走到了D.或者也可能将L和R互换,当然也可能都没有互换过,当然也可…
题目链接:http://codeforces.com/contest/811/problem/E 题意:给定一个行数为10 列数10w的矩阵,每个方块是一个整数, 给定l和r 求范围内的联通块数量 所谓联通块即数字相等 题解:显然可以用线段树来维护一下,一共就10行.线段树唯一难处理的就是push_up不好弄,这一要利用一下并查集,因为求的是连通块 的个数.具体看一下代码的注释. #include <iostream> #include <cstdio> #include <…
题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后能够得到该排列. 题解 将原排列拆分为一个个连续子序列,每次从大于上一子序列首部的元素处分出下一连续子序列,只要将这些子序列按照拆分先后排列,归并排序后一定可以得到原排列. 之后即判断能否将这些子序列排列为两个长为 $n$ 的序列即可,可以用状压 $dp$,也可以用 $01$ 背包. 状态 $dp$…
题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <cty…
题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a sequence a, consisting of n integers. We'll call a sequence…
题目链接: https://codeforces.com/contest/1152/problem/D 题意: 给出一个$n$,然后在匹配树上染色边,每个结点的所有相邻边只能被染色一次. 问,这颗树上最多染色多少边. 匹配树,就是深度为$2n$的树,每个节点都是一个字符串,只包含$(,)$,以长度为$2n$的合法匹配字符串作为叶子.每个节点的父亲是比自身长度小一的节点. 数据范围: $1 \le n \le 1000$ 分析: 在百度找了很久都没找到满意的题解,于是看了cf给的官方题解.虽然是全…
题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\) 叉高度为 \(1\) 的堆. 若 \(m > 1\) ,则 \(p\) 需要有至少 \(k\) 个儿子满足在儿子处有一个 \(k\) 叉高度为 \(m − 1\) 的堆. 令 \(dp[p][k]\) 表示在 \(p\) 点 \(k\) 叉堆的最大高度,令 \(g[p][k]\) 为 \(p\)…
题目链接:http://codeforces.com/problemset/problem/766/C 题意 有一个长度为n的字符串,第二行有26个数字,位置1~26对应为a~z的字母,数值表示该字母不能出现在长度超过该值的子串中. 求有多少种划分该字符串的方法 求该字符串划分成子串后最大的子串的长度 求该字符串划分成满足要求的子串需要至少划分多少次 AC代码 #include <stdio.h> #include <string.h> #include <iostream&…
E. Let's Go Rolling! time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assu…
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 'L':lose 'W':win '?':任意 'D':平局 输出一个字符串满足条件(Roma n局后离开要满足上述两个其中之一) 分析 dp题 令dp[i][j]表示进行i-1局比赛后,是否获得j个bourle. 如果第i局为'W': dp[i+1][j+1]=j; 如果第i局为'L':dp[i+…
C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces to n, and some of them…
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of n letters 'a'. He is too lazy to write a generator s…
题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结点 $u$ 有 $1$ 个子结点,添加 $2$ 个子结点 如果结点 $u$ 有 $3$ 个子结点,跳过该结点 如: \begin{equation} level = 1, 2, 3,4 \end{equation} 爪形结构如下: 问可以在 $level_n$ 选出几个互不相交的爪形结构. 题解 衍…
upd on 2021.7.7:修了个 typo Codeforces 题目传送门 & 洛谷题目传送门 首先考虑怎样处理"字典序小"这个问题,按照字典序比大小的套路,我们可以枚举第一位 \(p_x\ne q_x\) 的位置 \(x\),那么必然有 \(p_x<q_x\),为了避免后面计算中出现太多形如 \(n-x\) 之类的东西,我们不枚举 \(x\),instead 我们枚举 \(i=n-x\),那么真正的 \(x\) 等于 \(n\) 减去你枚举的 \(i\). 接下…
题目大概说给n个各有价值的硬币,要从它们中选出若干个组合成面值k,而要求的是各个方案里这些选出的硬币能组合出来的面值有哪些. 有点绕.. dp[i][j][k]表示前i个硬币中 能否 组合成面值j且选出的硬币能组合成面值k 转移要考虑全面..三个方向转移,第i个不选.第i个选但不参与选出硬币去组合成k.第i个选且参与选出硬币去组成成k #include<cstdio> using namespace std; ][][]; int main(){ int n,K,a; scanf("…
题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为d 的路径有多少条. 思路:d[i][l][sum] 表示第i 行最大值为l, 总和为sum的路径数. 注意:我的代码中 sum + j 有可能会超过数组最大值,即越界,刚开始我以为不会产生影响,后来 发现不知道为什么 在数组里越界以后比如 越界到d[][][111] 会对 d[][][1]产生影响…
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j]$:以i为结尾选择j个数字的最大和. $dp[i][j]=max(dp[i][j],dp[s][j-1]+a[i])$,$s为区间[i-k,i)$. 以i为结尾的最大和可以由i之前k个位置中的其中一个位置选择j-1个,再加上当前位置的ai得到. #include <cstdio> #includ…
Greenhouse Effect time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over th…
Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After the…
Codeforce 811 C. Vladik and Memorable Trip 解析(思維.DP) 今天我們來看看CF811C 題目連結 題目 給你一個數列,一個區段的數列的值是區段內所有相異數的\(XOR\)總和.你可以選任意多的區段,求最大的所有區段的值的總和.然而所有同樣的數字不是完全沒有被包含在區段裡,不然就是要全部在同個區段裡. 前言 這題我一直到看了解答才知道為什麼不是\(O(n)\),題目一直沒搞清楚 @copyright petjelinux 版權所有 觀看更多正版原始文章…
C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you ab…
C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you ab…
Vladik and Memorable Trip CodeForces - 811C 有一个长度为 n 的数列,其中第 i 项为 ai. 现在需要你从这个数列中选出一些互不相交的区间,并且保证整个数列中所有相同的数都在同一个区间中或都不在任意一个区间中. 要求最大化每个区间所有数去重后的异或和的总和.输出这个总和. 预处理出每个数字第一个出现的位置和最后一个出现的位置.以及每个区间内不同数字的异或和. dp[i]表示考虑到前i个数,最大值是多少.分情况讨论一下即可. #include <cst…
LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/A 题目: Description By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome.…
lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/C 题目: Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two n…
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2066" target="_blank" style="">题目链接 题目大意:给你n种不同颜色的弹珠.然后给出每种颜色的弹珠的个数,如今要求你将这些弹珠排序,要求同样颜色的部分最多3个.然后同样颜色的弹珠称…
[POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted: 2222 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all tea…