题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类有多少. 递推,dp[i]表示长度为i的种类有多少.当i < k的时候 dp[i] = 1 , 当i == k的时候 dp[i] = 2 ,  否则 dp[i] = dp[i - 1] + dp[i - k] . #include <bits/stdc++.h> using namespac…
题意:一个台阶由一些单元格组成,如果一个高度为\(n\)的台阶中有\(n\)个不相邻的正方形(如图中的样例),就称这个台阶是"好台阶",现给你\(x\)个单元格,问最多能组成多少个"好台阶"? 题解:题目数据范围最多给了\(10^{18}\),而样例中的\(10^{18}\)最多有\(30\)个好台阶,而前几个"好台阶"的个数我们可以手算出来发现递推规律,\(f[i]=f[i-1]*2+(2^{i-1})^2\),所以我们预处理出来前\(30\)…
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, s…
D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At…
D. Flowers   We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of sever…
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 模拟一下就好了 代码 #include<bits/stdc++.h> using namespace std; string s[3]; map<char,int>r,c; char ss[2][107]; int main() { s[0]="qwertyuiop"…
很简单的递推题.d[n]=d[n-1]+d[n-k] 注意每次输入a和b时,如果每次都累加,就做了很多重复性工作,会超时. 所以用预处理前缀和来解决重复累加问题. 最后一个细节坑了我多次: printf("%I64d\n",(s[b]-s[a-1]+mod)%mod); 这句话中加mod万万不能少,因为理论上s[b]-s[a-1]肯定大于0,但是由于两个都是模1000000007以后的结果,那么就不一定了,当s[b]-s[a-1]<0时结果是负的,不是题意中应该输出的结果,所以一…
前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<string.h> #include<math.h> #include<algorithm> #include<stdio.h> #include<math.h> #include<string> #include<iostream> us…
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <que…
A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<algorithm> using namespace std; typedef long long LL; ]="qwertyuiopasdfghjkl;…