C. Vladik and Memorable Trip DP】的更多相关文章

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…
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…
Vladik and Memorable Trip CodeForces - 811C 有一个长度为 n 的数列,其中第 i 项为 ai. 现在需要你从这个数列中选出一些互不相交的区间,并且保证整个数列中所有相同的数都在同一个区间中或都不在任意一个区间中. 要求最大化每个区间所有数去重后的异或和的总和.输出这个总和. 预处理出每个数字第一个出现的位置和最后一个出现的位置.以及每个区间内不同数字的异或和. dp[i]表示考虑到前i个数,最大值是多少.分情况讨论一下即可. #include <cst…
<题目链接> 题目大意: 给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都只能出现在这个区间. 每个区间的价值为该区间不同的数的异或值之和,现在问你这n个数最大的价值是多少. 解题分析:因为要同一种的所有数只能出现在同一区间,所以我们先对这$n$个数进行预处理,得到他们每种数的最左边的坐标和最右边的坐标.因为数据只有5000,所以状态可以比较暴力地更新,枚举最后一个异或的区间进行更新,用dp值来记录. $dp[i]$表示$[1,i]$中异或值之和的最大值.第$i$个可以选或…
http://codeforces.com/contest/811/problem/C [题意] 给定一个自然数序列,在这个序列中找出几个不相交段,使得每个段的异或值之和相加最大. 段的异或值这样定义:段中每个不同数字(不重复)相异或. 段有这样的要求:段中任意一个数字不会在段外出现. [思路] 首先预处理每个数字第一次出现和最后一次出现的位置,这样对于一个区间[l,r]就很容易判断是否为满足题意的段. 然后区间DP,dp[i]表示子序列[1,i]的最大值. 状态转移:对于dp[i],最小值为d…
题目链接:http://codeforces.com/contest/811/problem/C 题意:给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都要出现在这个区间. 每个区间的价值为该区间不同的数的异或值,现在问你这n个数最大的价值是多少. 题解:一般这种说法的题目都是用dp的,然后显然设dp[i]表示前i个能取得的最大价值,然后再存一下每个数的起始位置和 结束位置然后n*n就可以了,具体看一下代码,挺短的. #include <iostream> #include…
$dp$. 记录$dp[i]$表示以位置$i$为结尾的最大值. 枚举最后一段是哪一段,假设为$[j,i]$,那么可以用$max(dp[1]...dp[j-1]) + val[j][i]$去更新$dp[i]$. 判断区间是否合法可以记录选择每个位置必须需要取到的最小位置和最大位置,判断区间合法性的时候就只需判断区间内每一个数字的最小位置和最大位置是否均在该区间内. #include <iostream> #include <cstdio> #include <cstring&g…
思路: 令dp[i]表示前i个的最大舒适度.则如果区间[j, i](1 < j <= i)满足条件,有如下转移:dp[i] = max(dp[i], dp[j - 1] + cur).其中,cur为区间[j, i]的舒适度. 实现: #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; int n, a[MAXN], l[MAXN], r[MAXN],…
原题链接:http://codeforces.com/contest/811/problem/C 题意:将数组中的连续数字连成若干个“线段”(或者不连),其实就是区间.区间必须满足对于其中的任意数字,能够覆盖数组中的所有相等数字,比如对数组:1, 2, 5, 2 ,5,    [2, 5 ,2 ,5]是满足条件的区间,而[2, 5, 2]不是,因为它并没有包含所有的5. 题目求不相交的满足条件的区间内不同数字的异或和的最大值. 思路:这是一道普通的DP题,类似最长上升子序列,先求出每个数字的最长…
http://codeforces.com/contest/811/problem/C 题意: 给出一行序列,现在要选出一些区间来(不必全部选完),但是相同的数必须出现在同一个区间中,也就是说该数要么不选,选了就必须出现在同一个区间,最后累加区间不同的数的异或值. 思路: 先预处理,求出每个数的左位置和右位置. d[i]表示分析到第 i 位时的最大值. #include<iostream> #include<algorithm> #include<cstring> #i…
划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列.  一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和.    求整个的价值的最大值   f(i)表示最后一个划分序列的右端点为i时,1~i的答案. f(i)=max{max{f(j)}(1<=j<i)+xorsum(j+1,i)(j+1到i的区间合法)}(1<=i<=n) 需要在转移的时候,顺便处理f(i)的前缀max. 最终的答案就是所有f…
[题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定没什么用. 还不如当时初学者的时候的\(dp(i,j)\)表示考虑到\(i\)考虑到\(j\)的LCS...果然经典的是禁得起考验的... 考虑如何记录方案,第一个想法是直接暴力记录从哪转移的,但是这样显然不行.因为有很多重复的元素. 注意到题目保证本质不同的满足答案要求的串的个数是\(O(n)\)…
B - Byteland Trip 题目大意:给你一个由'<' 和 '>'组成的串, 如果在'<' 只能前往编号比它小的任意点, 反之只能前往比它大的任意点,问你能遍历所有点 并且每个点只走一次终点在各个位置的方案数. 思路:感觉这种右能从左边跑到右边又跑回来的dp很难搞,如果我们确定一个终点, 如果知道它左边点一共出来几次,右边的点一共出来几次 那么方案数就很好求了, 所以我们定义dp1[ i ][ j ] 表示前 i 个点,遍历所有点并且向右出去 j 次的的方案数, dp2[ i ]…
http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Vladik discovered a new entertainment — coding bots for social netwo…
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. Afte…
    A CodeForces 811A Vladik and Courtesy   B CodeForces 811B Vladik and Complicated Book   C CodeForces 811C Vladik and Memorable Trip     D CodeForces 811D Vladik and Favorite Game     E CodeForces 811E Vladik and Entertaining Flags 点击题号进入题面 ------…
A. Vladik and Courtesy 题面 At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same…
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. Afte…
A. Vladik and Courtesy 水题略过 #include<cstdio> #include<cstdlib> #include<cmath> using namespace std; typedef long long int LL; int main() { LL a,b; scanf("%I64d%I64d",&a,&b); LL num=1; while(true) { if(a<num){printf(&…
Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29, Accepted users: 29 Problem 12882 : No special judgement Problem description You are planning a road trip to visit your friends, each of whom live in…
E. Vladik and cards 题目链接 http://codeforces.com/contest/743/problem/E 题面 Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not e…
题目链接:1484 - Alice and Bob's Trip 题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,可是有个条件,就是路径权值总和必须在[L,R]之间,求终于这条路径的权值. 思路:树形dp,dp[u]表示在u结点的权值,往下dfs的时候顺带记录下到根节点的权值总和,然后假设dp[v] + w + sum 在[l,r]内,就是能够的,状态转移方程为 dp[u] = max{dp[v] + w }(bob) dp[u] = m…
Alice and Bob's Trip Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2643    Accepted Submission(s): 708 Problem Description Alice and Bob are going on a trip. Alice is a lazy girl who wants to…
Trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3850   Accepted: 1030 Description Alice and Bob want to go on holiday. Each of them has planned a route, which is a list of cities to be visited in a given order. A route may contain a…
Trip Planning Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4261 Description   You are going on a long trip. Initially, you stay at hotel 0. Along the way, there are n<tex2html_verbatim_mark&g…
题目链接 Mahmoud and a xor trip 树形DP.先考虑每个点到他本身的距离和,再算所有点两两距离和. 做的时候考虑二进制拆位即可. #include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i(0); i < (n); ++i) #define rep(i, a, b) for(int i(a); i <= (b); ++i) #define LL long long const…
题意:给定n个人的m个对话,问能不能找一个方式使得满足,上下楼层人名不同,并且自己不提及自己. 析:首先预处理每一层能有多少个user可选,dp[i][j] 表示第 i 层是不是可以选第 j 个user.最后再输出即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib>…
题解: 二营长!你他娘的意大利炮呢? dp[i][j][0]: 从i,跋涉到以i为根的子树的每一个节点,在第j个数位上一共产生了多少个0. dp[i][j][1]: 从i,跋涉到以i为根的子树的每一个节点,在第j个数位上一共产生了多少个1. 转移式:(cur为i的儿子,t = (a[i]>>j)&1) dp[i][j][0^t] += dp[cur][j][0]; dp[i][j][1^t] += dp[cur][j][1]; 初始化: dp[i][j][0] = (t==0); dp…