Alexander Charles McMillan loves to gamble, and during his last trip to the casino he ran across a new game. It is played on a linear sequence of squares as shown below. A chip is initially placed on the Start square. The player then tries to move th…
题目要求一个最大的弱联通图. 首先对于原图进行强连通缩点,得到新图,这个新图呈链状,类似树结构. 对新图进行记忆化dp,求一条权值最长的链,每一个点的权值就是当前强连通分量点的个数. /* Tarjan算法求有向图的强连通分量set记录了强连通分量 Col记录了强连通分量的个数. */ #include <iostream> #include<cstring> #include<cstdio> #include<string> #include<alg…
题目传送门 题意:训练指南P217 分析:没有模板串也就是在自动机上走L步,不走到val[u] == v的节点的概率 PS:边读边insert WA了,有毒啊! #include <bits/stdc++.h> using namespace std; const int K = 20 + 5; const int L = 100 + 5; const int NODE = K * K; const int SIZE = 66; int idx[256], n; struct AC { int…
题意:和最长滑雪路径一样, #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> #define mod=1…
这题和上次的通化邀请赛的那题一样,而且还是简化版本... 那题的题解      请戳这里 ... #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; #define INF 0x3f3f3f3f int dp[105][105]; int a[105]; int sum,n; int pre_sum[105],next_s…
UVA 1541 - To Bet or Not To Bet 题目链接 题意:这题题意真是神了- -.看半天,大概是玩一个游戏,開始在位置0.终点在位置m + 1,每次扔一个硬币,正面走一步,反面走两步,走到的步上有4种情况: 1.向前走n步 2.向后走n步 3.停止一回合 4.无影响 问能在t次机会内,走到终点m + 1(假设跃过也算走到了)的概率.大于0.5.等于0.5,小于0.5相应不同输出 思路:题意懂了就好办了.事实上就是递推就能够了dp[i][j]表示第i次机会,落在j步的概率.然…
To Bet or Not To Bet Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1668 Accepted: 541 Description Alexander Charles McMillan loves to gamble, and during his last trip to the casino he ran across a new game. It is played on a linear seque…
题目链接:uva 10581 - Partitioning for fun and profit 题目大意:给定m,n,k,将m分解成n份,然后依照每份的个数排定字典序,而且划分时要求ai−1≤ai,然后输出字典序排在k位的划分方法. 解题思路:由于有ai−1≤ai的条件.所以先记忆化搜索处理出组合情况dp[i][j][s]表示第i位为j.而且剩余的未划分数为s的总数为dp[i][j][s],然后就是枚举每一位上的值.推断序列的位置就可以. #include <cstdio> #include…
题目:UVA - 10118Free Candies(记忆化搜索) 题目大意:给你四堆糖果,每一个糖果都有颜色.每次你都仅仅能拿随意一堆最上面的糖果,放到自己的篮子里.假设有两个糖果颜色同样的话,就行将这对糖果放进自己的口袋.自己的篮子最多仅仅能装5个糖果,假设满了,游戏就结束了.问你可以得到的最多的糖果对数. 解题思路:这题想了好久,好不easy把状态想对了,结果脑子发热,又偏离了方向.dp[a][b][c][d]:四堆糖果如今在最上面的是哪一个.由于以下的糖果假设确定了,那么接下了无论你怎么…
Problem    UVA - 10917 - Walk Through the Forest Time Limit: 3000 mSec Problem Description Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To…