Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × k square, divided into unit squares. Please note that k ≥ 3 and is odd. We'll paint squares starting from the upper left square in the following orde…
题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了非常久也没有想出来,有点无从下手的感觉,最后还是尝试了一下记忆化搜索,以dp[0][0]为边界,dp[x][y]代表当前有x行y列没有彩色的 瓷砖,搜索起来思路还是非常清晰的,可惜最后那个 算期望公式给写错了,瞎了好久,做出以后看了一下别人的做法,确实有点难想到,把涂好的都放在右下角,这样就仅仅有四…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game ju…
Description A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward"). Y…
题目链接:Playing Piano 题意:给定长度为n的序列$a_i$,要求得到同样长度的序列$b_i$.满足一下条件: if $a_i < a_{i+1}$ then $b_i < b_{i+1}$ if $a_i > a_{i+1}$ then $b_i > b_{i+1}$ if $a_i = a_{i+1}$ then $b_i \neq\ b_{i+1}$ $1 <= b_i <= 5$ 题解:第一个数从1-5枚举,接着从下一位开始搜索,dp[i][j]表示…
链接 Codeforces 667C Reberland Linguistics 题意 给你一个字符串,除去前5个字符串后,使剩下的串有长度为2或3的词根组成,相邻的词根不能重复.找到所有的词根 思路 去掉前5个字符,将剩下的串反过来进行记忆化,用vis[last][pos]记录一下当前状态是否做过.last是之前与之相邻的词根.比赛的时候只用了vis[i]错了. 代码 #include <iostream> #include <cstdio> #include <vecto…
虽然不是正解但毕竟自己做出来了还是记下来吧- 对每个人分别dfs得到其期望,某两维的组合情况有限所以Hash一下避免了MLE. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; const int maxn = 51, mod = 998244353;…
A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer…
Voracious Steve 题目连接: http://codeforces.com/gym/100231/attachments Description 有两个人在玩一个游戏 有一个盆子里面有n个甜甜圈,A先开始,他可以抓[1,min(m,n)]颗甜甜圈,然后B开始,同样,可以抓[1,min(n,m)]个甜甜圈 谁抓完的,就可以把自己抓的吃完,然后另外一个人就把他的甜甜圈扔进去,然后由失败的那个人开始 问你第一个人最多能吃到多少个甜甜圈 Input 2个整数 n,m 表示一开始有n个甜甜圈,…
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…
E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/E Description You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break…
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes. A string is 1-palindrome if and only if it reads the same backward as f…
D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that…
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公主先拿. 公主每次抓一只出来.龙每次在抓一只出来之后,会随机有一只老鼠跳出来(被龙吓的了...). 先抓到白老鼠的人赢.若两人最后都没有抓到白老鼠,则龙赢. 问你公主赢的概率. 题解: 表示状态: dp[i][j] = probability to win(当前公主先手,公主赢的概率) i:剩i只白…
题目链接:http://codeforces.com/contest/284/problem/D 题意:给出n个数,奇数次操作x,y都加上a[x],偶数次操作y加上a[x],x减去a[x],走出了范围就结束. 问结束时的y值,如果无法结束,那么输出-1 题解:很显然可以用记忆化搜索来解决,可以设dp[i][j](i=0表示偶数次操作以j为结尾的y值是多少,i=1表示奇数次操作以j为结尾的y值是多少) 在加一个辅助的vis[i][j](i=0表示偶数次操作以j为结尾有没有取过,i=1表示奇数次操作…
题目链接:http://codeforces.com/contest/793/problem/D 题意:给出n个点m条边选择k个点,要求k个点是联通的而且不成环,而且选的边不能包含选过的边不能包含以前 选过的点,问最小的权值是多少. 题解:像这种取最小的一般可以考虑一下dp,然后再看一下题目,由于每次选的边都不能包括以前选的点,所以每 选择一条边能选择的区间范围就缩小了. 设dp[pos][l][r][k](这里可能会有人觉得开80*80*80*80会不会有点大了,自行计算一下不会爆内存的),p…
https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没有公共点,问边集大小 题解 对于一颗字典树,从低向上贪心,最底层的边全拿,定义好状态,记忆化搜索计数 定义dp[i][j]为左括号数量为i,右括号数量为j的最大边集 \(i<n\),\(dp[i][j]->dfs(i+1,j)\) \(j<i\),\(dp[i][j]->dfs(i,j…
https://codeforces.ml/contest/1746/problem/D 题目大意:一棵n节点有根树,根节点为1,分别有两个数组 s[i] 顶点 i 的魅力值 c[i] 覆盖顶点 i 的路径数 每个顶点的路径数必须满足,同一父节点的子节点| c[v1]-c[v2] | <= 1 问当有k条路径时,∑c[i]*s[i]的最大值 思路: 因为同一父节点的子节点 | c[v1]-c[v2] | <= 1,所以对于父节点来说,每次都需要平分路径数,如果有多余的路径则考虑 分给贡献最大的…
题目 记忆化搜索(深搜+记录状态) 感谢JLGG //记忆话搜索 //一本书2中状态,竖着放或者横着放 //初始先都竖着放,然后从左边往右边扫 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ][][];//dp[第几个][厚度][宽度] int n; ],b[]; int rec(int i,int th,int w) { )return dp[i][th][w…
E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output In a two player card game, you have nn minions on the board and the opponent has mm minions. Each minion has a health between 11 a…
题意:有N种物品,每种物品有价值\(a_i\),每种物品可选任意多个,求拿k件物品,可能损失的价值分别为多少. 分析:相当于求\((a_1+a_2+...+a_n)^k\)中,有哪些项的系数不为0.做k次FFT求卷积求卷积肯定爆炸,考虑用分治的形式计算,因为中间计算的时候会重复计算一些幂次,所以用记忆化搜索的形式,保留计算结果. 因为只要计算出哪些项不为0,所以卷积之后求结果时,系数非0项用1作系数即可,否则分分钟炸精度. 当然也可以用快速幂求解#. #include <bits/stdc++.…
题意 在一个有向无环图上,两个人分别从一个点出发,两人轮流从当前点沿着某条边移动,要求经过的边权不小于上一轮对方经过的边权(ASCII码),如果一方不能移动,则判负.两人都采取最优策略,求两人分别从每个点出发的胜负关系表. 分析 记忆化搜索. f[x][y][v]表示现在两人分别在x,y,上一轮经过的边权为v时x是否能胜利(胜利为1,失败为0). 考虑如何转移: 对于一条从x到u的边权为val的边,如果val>=v,则可以走这条边,算出f[y][u][val], 如果f[y][u][val]为0…
题目大意: 给定n m k:(1≤n≤1e5, 0≤m≤200, 1≤k≤1e5) 表示n个时间长度内 最多被打扰m次 k个红包 接下来k行描述红包 s t d w:(1≤s≤t≤d≤n , 1≤w≤1e9) 表示在 s 到 t 的时间内都可开始获得该红包 该红包在时间 d 时才能完成获得 红包内有w硬币 在同一时间段内只能获得一个红包 不能同时获得两个及以上 求在被打扰的情况下使获得的红包硬币最少 是多少 用in out标记各红包可被获得的区间 用multiset维护在某个时间点可获得的红包有…
http://codeforces.com/contest/752/problem/E 首先有一个东西就是,如果我要检测5,那么14我们认为它能产生2个5. 14 = 7 + 7.但是按照平均分的话,它是不能产生5的,那就把那两个7当成是两个5,因为7比5还大,对min(b[i])是没有影响的. 可以思考下样例2. 那么二分答案mid,设dp[val][x]表示val这个数字能产生多少个x.dp[val][x] = dp[val / 2][x] + dp[(val + 1) / 2][x] 那么…
Play Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 18 Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards i…
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly fac…
A and B are playing a shooting game on a battlefield consisting of square-shaped unit blocks. The blocks are occupying some consecutive columns, and the perimeter of the figure equals the perimeter of its minimal bounding box. The figure (a) below is…
Rikka with Nash Equilibrium Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1460    Accepted Submission(s): 591 Problem Description Nash Equilibrium is an important concept in game theory. Ri…
一般搜索 注意:一般定义成void Books Exchange (easy version)  CodeForces - 1249B2 The only difference between easy and hard versions is constraints. There are nn kids, each of them is reading a unique book. At the end of any day, the ii-th kid will give his book…
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> using namespace std; #define maxn 1000+5 int n; int a[maxn][maxn]; int d[maxn][maxn]; int main(){ for(;cin>>n && n;){ memset(d,,sizeof(d));…