Codeforces 408D Long Path (DP)】的更多相关文章

题目: One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each…
题目链接 题意:一共n+1个房间,一个人从1走到n+1,如果第奇数次走到房间i,会退回到房间Pi,如果偶数次走到房间i,则走到房间i+1,问走到n+1需要多少步,结果对1e9+7取模. 题解:设dp[i]表示从1走到i需要多少步,那么走到房间i+1需要dp[i+1]=dp[i]+1+x+1,这里面第一个1表示走完这步退回到Pi,这个x表示退回到房间Pi再走回来的步数,第二个1表示走完这步到达i+1.我们发现:1.当走到房间Pi的时候,Pi+1到i都是没有走过的即为0次:2.当走到房间i的时候,P…
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列上可以向上走,其他列不能向上走.可以重复经过同一个点.求从(1,1)出发,经过所有宝藏的最短路径长度 \(n,m,k,q \leq 2 \times 10^5\) 分析 贪心考虑,我们应该按照行一层一层的走.每一行应该从最左的宝藏走到最右的宝藏,或者从最右的宝藏走到最左的宝藏,然后找最近的一个可以向…
题目链接:http://codeforces.com/problemset/problem/407/B 题目大意:一共n+1个房间,一个人从1走到n+1,每次经过房间都会留下一个标记,每个房间有两扇门:①第一扇门通向i+1,如果当前房间标记有奇数个,则必须走第一扇门.②第二扇门通向pi(pi<=i),如果当前房间标记有偶数个,则必须走第二扇门.问从房间1走到房间n+1需要多少步,结果对1e9+7取模.解题思路:之前傻了...明明都推出规律了,结果被自己给否定了...设dp[i]表示从1~i需要走…
题目链接:http://codeforces.com/contest/762/problem/D 多多分析状态:这个很明了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define…
题目链接: Find a path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1557    Accepted Submission(s): 678 Problem Description Frog fell into a maze. This maze is a rectangle containing N rows and M …
Find a path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1536    Accepted Submission(s): 673 Problem Description Frog fell into a maze. This maze is a rectangle containing N rows and M column…
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…
题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city,…
题目链接: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…