http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1317经典问题:树上最长路,边权可以为负值的,树形dp,不能用两边dfs.反例:5 41 2 22 3 12 4 -1004 5 10写树形dp的时候,WA了好多次,错误在于:记录单链的时候,一个节点的最长单链不一定等于:边权+孩子的最长单链还可以不选孩子,只要边权就行!!!!!!如果边权非负的话,就是 边权+孩子的最长单链 了. 思路: dp[u][0],记录的是以u为根结点的子树中的最长路 d…
ZJK的黑OJ zjk开了一家"善良OJ".这其实是家黑OJ.每AC一道题,网站便会自动在电脑上安装一种木马.zjk通过窃取信息获取收益(如网游帐号.OI资料.和KK的照片等等). 作为一名资深黑客,老Z某日突然发现,"善良OJ"上的木马,自己电脑上都没有.这可十分让他过意不去.老Z决定通过多A题,来丰富自己电脑的病毒库. 经过调查,老Z发现,很多木马是不能共存的.比如"和谐"木马与"团结"木马,两者只能任选其一.然而,老Z是…
Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. It is actually a huge cavern, which consists of many rooms connected with tunnels. Each room is occupie…
Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3623    Accepted Submission(s): 1684 Problem Description There is going to be a party to celebrate the 80-th Anniversary of the…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1336 There is an interesting calculator. It has 3 rows of buttons. Row 1: button 0, 1, 2, 3, ..., 9. Pressing each button appends that digit to the end of the display. Row 2: button +0, +1, +2, +3, ...…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1352 题意:就是要将7 1 5 2这样的序列变成1  2  5  7最少需要多少步?给出变的规律,每次把最前面的那个数移动到比它次小的数的后面,要是它后面没有比它次小的数,就移动到最后,问最少需要多少步? For example, we will use 7 steps to sort the sequence 7 1 5 2:    7 1 5 2 --> 1 5 7 2 --> 5 7 2…
n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[n]*n 记为w 当中dp[i]为i个人扔中的概率 dp[i] = C(n, i)*p^i*(1-p)^(n-i) 终于答案为w*k #include <cstdio> #include <cstring> using namespace std; double dp[20]; dou…
Description You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly differen…
Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6990    Accepted Submission(s): 3104 Problem Description There is going to be a party to celebrate the 80-th Anniversary of the…
题意: 一个图, 点权代表走到该点可获得的能量值. 可正可负. 一个人从1 号出发,带有100点能量. 问是否有一种方案可使人在能量值>0的时候走到n. 思路: 这个题首先要注意点权. 其实就是这点的所有入边的边权都等于这点的点权. 要找长路, 而非最短路. 但是可以借助最短路的算法SPFA求. 最短路的算法SFPA主要是 队列 + 松弛 松弛操作直接关系到我们运行算法的目的----求最短路 如果与该点相邻的下一个点到源的距离可以因为通过该点中转而缩短 ,则更新此下一个点到源的最短距离, 也就相…