CodeForces 721B Journey (DP)】的更多相关文章

题意:给定一个有向图,你从1出发到n,走尽可能多的点,并且使总权值不大于t. 析:在比赛时,竟然看成有向图了,就想了好久,感觉dp,但是不会啊...如果是有向图就好做多了,枚举边,然后打印就好,dp[i][j] 表示, 经过 i 个结点,并且在 j的最小时间. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #inc…
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #include <bits/stdc++.h> using namespace std; const int N = 100005; int n; vector<int> G[N]; double dp[N], val[N]; bool vis[N]; void dfs(int u, i…
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to one of the most famous cities of Berland - the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected…
题目链接:http://codeforces.com/contest/721/problem/C 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 Berlato…
题目链接: 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,…
<题目链接> 题目大意:一个DAG图有n个点,m条边,走过每条边都会花费一定的时间,问你在不超过T时间的条件下,从1到n点最多能够经过几个节点. 解题分析:对这个有向图,我们进行拓扑排序,并且在拓扑排序的过程中,用dp来进行状态的转移,$dp[i][j]$表示,在以$i$为终点的且经过$j$个点的路径中,所花的最少时间. #include <bits/stdc++.h> using namespace std; #define pb push_back ; int dp[N][N]…
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, numbe…
1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径,经过的点数要最多. #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,…
题目链接:http://codeforces.com/contest/682/problem/D 思路:dp[i][j][l][0]表示a串前i和b串前j利用a[i] == b[j]所得到的最长子序列, dp[i][j][l][1]表示a串前i和b串前j不利用a[i] == b[j]所得到的最长子序列, 所以,dp[i][j][l][0] = max(dp[i-1][j-1][l][0] ,max(dp[i-1][j-1][l-1][0],dp[i-1][j-1][l-1][1])) + 1 d…
题目链接:http://codeforces.com/problemset/problem/666/A 思路:dp[i][0]表示第a[i-1]~a[i]组成的字符串是否可行,dp[i][1]表示第a[i-2]~a[i]组成的字符串是否可行,显然dp[len-2][0(1)]必定不可行. 转移方程: dp[i][0] = dp[i+3][1] || dp[i+2][0] && (tmp1 != tmp2); dp[i][1] = dp[i+2][0] || dp[i+3][1] &…