Codeforces 356D Bacterial Melee dp】的更多相关文章

Bacterial Melee 我们发现所有合法串都是原序列的某个子序列(这个子序列相邻元素相等) 的扩展, 比如子序列为abc, 那么aabbbc, abbbcc 等都是合法串. 所以我们只需要dp出原串有多少相邻元素不同的子序列就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL&…
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列上可以向上走,其他列不能向上走.可以重复经过同一个点.求从(1,1)出发,经过所有宝藏的最短路径长度 \(n,m,k,q \leq 2 \times 10^5\) 分析 贪心考虑,我们应该按照行一层一层的走.每一行应该从最左的宝藏走到最右的宝藏,或者从最右的宝藏走到最左的宝藏,然后找最近的一个可以向…
大意: 给定字符串, 每次可以任选一个字符$x$, 将$x$左侧或右侧也改为$x$, 求最终能得到多少种字符串. 首先可以观察到最终字符串将连续相同字符合并后一定是原字符串的子序列 并且可以观察到相同长度(设为m)的子序列能产生的最终字符串种类数是相同的. 即$\binom{n-1}{m-1}$ (可以通过排列后m-1个字符首次出现位置得到). 然后问题就转化为求原字符串相邻字符不同且本质不同的子序列个数. 前缀优化一下复杂度为$O(n^2)$ #include <iostream> #inc…
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits:  200000 KB 64-bit interger IO format:  %lld   Java class name:  Main Description A Hill Number is a number whose digits possibly rise and then possibl…
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍),问要获得长度为n的串所需最少的时间. 思路:dp[i]表示获得长度为i的串所需要的最短时间,分i为奇数和偶数讨论. #include<bits/stdc++.h> using namespace std; const int N=1e7+3; typedef long long ll; ll…
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; int dp[105][3]; int main() { int n; scanf("%d",&n); memset(dp,INF,sizeof(dp)); d…
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+3; const ll INF=1e18; ll dp[N][2]; string a[N],b[N]; int c[N]; int main() { int n; scanf("%d",&n); for(…
Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word in…
http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve…
http://codeforces.com/contest/711 C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where…