D. Zuma   Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos i…
Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串:每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因为只需要考虑一边),当考虑最左边的数时,有多少中消去方法?每种消去方法对结果的贡献又是多少?同时结果的区间又是怎么变化?这就是dp式子: 1.当单独消去这个元素时,dp[l][r] = 1 + dp[l+1][r]; 2.当存在一个k,l< k <= r,使得c[l] == c[k]时,可以认为在…
B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string…
题目链接:https://codeforces.com/contest/608/problem/D 题意:给出n个宝石的颜色ci,现在有一个操作,就是子串的颜色是回文串的区间可以通过一次操作消去,问最少需要多少次操作可以消除所有的宝石.(每次操作消除一个回文串,最少操作次数清楚字符串) 题解:dp[l][r]表示区间(l,r)的最少操作次数,对于一个区间(l,r),有两种转移:①若存在c_l = c_i(l <= i <= r),可以由dp[l][i] + dp[i + 1][r]转移:②若c…
D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gems…
C. Chain Reaction   There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) w…
#include<bits/stdc++.h>using namespace std;int a[5007];int dp[5007][5007];int main(){    int n; scanf("%d",&n);    for(int i=1;i<=n;i++)        scanf("%d",&a[i]);    n=unique(a+1,a+1+n)-a-1;    for(int i=n;i>=1;i--)…
C. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. Wh…
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记忆化搜索记忆,vis数组标记那些已经访问过的状态. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define REP(i, a, b) for (i…
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an eleva…