随笔分类 - POJ
摘要:题意:给一棵树,每个节点都有一个权值,权值只能拿一次,只让走K步,问最多能拿到多少权值这个题目一开始没料到原来可以往回走,分析了样例才知道。之后我用DFS搜索,超时后来一直想树形DP的状态转移,一直没想出来。后来还是看别人博客上的状态转移方程。dp[0][rt][j+2]=max(本身,dp[0][rt][w]+dp[0][nx][j-w])//w为枚举的需要多少步,由于要从nx子节点返回,故需要比j多两步dp[1][rt][j+2]=max(本身,dp[1][rt][w]+dp[0][nx][j-w])//走向子树后回来再一去不回,因为从子树回来需要多走两步dp[1][rt][j+1]=ma
阅读全文
摘要:Cell Phone NetworkTime Limit:1000MSMemory Limit:65536KTotal Submissions:5325Accepted:1886DescriptionFarmer John has decided to give each of his cows a cell phone in hopes to encourage their social interaction. This, however, requires him to set up cell phone towers on hisN(1 ≤N≤ 10,000) pastures (co
阅读全文
摘要:最近做DP题目,发现无论是LCS,还是有些题目涉及将动态规划的路径打印出来,而且有时候还要按格式输出,这个时候,记忆化搜索显得尤其重要,确实,记忆化搜索使用优化版本的动态规划,用起来思路清晰,非常方便这个题目就是一个n*n的图里,从起点出发,只能横向或者纵向走最多k步,而且每次下个点都要比当前点的值要高,这样最终走完获得的总点权值最大是多少明显的是一BFS 或者DFS,当然,我们稍微优化下,用记忆化搜索,就会成为很优化版本的DFS。所以从代码看,这样的记忆化搜索,其实是从起点出发,但是最终要搜到最后一点,然后层层返回,此时,每个得到了返回值的点都已经是最优点了,所以下次再搜到这个点直接返回,这
阅读全文
摘要:话说DP=记忆化搜索这句话真不是虚的。面对这道题目,题意很简单,但是DP的时候,方向分为四个,这个时候用递推就好难写了,你很难得到当前状态的前一个真实状态,这个时候记忆化搜索就派上用场啦!通过对四个方向进行搜索,即可得到当前状态的最优解。#include #include using namespace std;int date[105][105];int dp[105][105];int dir[][2]= {{0,1},{0,-1},{1,0},{-1,0}};int r,c;int dpac(int i,int j){ if (dp[i][j]>1) return dp[i][j]
阅读全文
摘要:第一次涉及HASH查找的知识对于字符串的查找有很多前人开发出来的HASH函数,比较常用的好像是ELF 和 BKDR。这道题没想到突破点是在于其nc值,告诉你组成字符串的字母种类。还有用26进制,不管怎么说,只要避免产生冲突,怎么哈希都行。用的是BKDRHash法。#include #include #include #define maxn 20000000#define mm 1000000using namespace std;int hash[maxn]={0};char str[mm];int news[mm]={0};int ans;int n,nc;int BKDRHash(cha
阅读全文
摘要:DescriptionThe cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as their vacation residence. This immense hotel h
阅读全文
摘要:题目大意:依次描述了一个N个人的队伍,每个人所站的序号以及他的价值,依次描述每个人的过程中,存在序号相同的人,表示该人插入到了前一个序号相同的人的前面。最后输出整个队伍的值排列情况。这个题目确实难以想到居然可以用线段树做,之前还脑残去敲什么链表,结果发现链表这玩意儿真不是一般的垃圾,好多地方根本就无法对时间进行优化。当然了,就算告诉了你用线段树做,可能还是会很头疼,这里涉及插队操作。。而且线段树具体是存放什么东西的呢线段树就是为了模拟当前队伍的空位数,比如一个4人队伍,Root肯定是值为4 然后左右孩子都为 2 2 ,最底下4个孩子均为1,表示该位置还可以插入几个人插队操作是比较蛋疼的,为了避
阅读全文
摘要:终于线段树还是有所领悟,发现对一个算法真的是,一开始云里雾里,后来这些天狂搞图论,数据结构,把KMP,Manacher,最短路,最小生成树 都狂弄了一下之后,发现再来弄线段树就容易多了,至少建树,更新什么的,我脑海里已经可以自己构图了。。所以,一个心得是,算法可以让脑子变的灵活聪明,前几天看的云里雾里的东西,过几天就会有领悟了。好了,进入正题。挑了一道还算可以的线段树题目,上午A了一道,完全是纯线段树水题,这题涉及懒惰标记,感觉高端了好多。。就算用了懒惰标记,仍然跑了将近3000MS,话说最近做图论题目发现,G++总是比C++要多几百MS(数据量本身比较大的时候)。。。而且尤其碰到几个坑题,用
阅读全文
摘要:Big Christmas TreeTime Limit:3000MSMemory Limit:131072KTotal Submissions:19029Accepted:4058DescriptionChristmas is coming to KCM city. Suby the loyal civilian in KCM city is preparing a big neat Christmas tree. The simple structure of the tree is shown in right picture.The tree can be represented as
阅读全文
摘要:A -OulipoTime Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64d & %I64uSubmitStatusDescriptionThe French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter'e'. He was a member of the Oulipo group. A quote from the book:Tout avait Pair normal, mais
阅读全文
摘要:PieTime Limit:1000MSMemory Limit:65536KTotal Submissions:8594Accepted:3124Special JudgeDescriptionMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each o
阅读全文
摘要:The SuspectsTime Limit:1000MSMemory Limit:20000KB64bit IO Format:%I64d & %I64u[Submit] [Go Back] [Status]DescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the b
阅读全文
摘要:Protecting the FlowersTime Limit:2000MSMemory Limit:65536KTotal Submissions:3204Accepted:1300DescriptionFarmer John went to cut some wood and leftN(2 ≤N≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating his beautiful
阅读全文
摘要:A -Card StackingTime Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64d & %I64uSubmitStatusDescriptionBessie is playing a card game with herN-1 (2 ≤N≤ 100) cow friends using a deck withK(N≤K≤ 100,000;Kis a multiple ofN) cards. The deck containsM=K/N"good" cards andK-M"bad"
阅读全文
摘要:POJ - 3258River HopscotchTime Limit:2000MSMemory Limit:65536KB64bit IO Format:%I64d & %I64u[Submit] [Go Back] [Status]DescriptionEvery year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on
阅读全文
摘要:POJ-3273 Monthly ExpenseTime Limit:2000MSMemory Limit:65536KTotal Submissions:10557Accepted:4311DescriptionFarmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has al...
阅读全文
摘要:Charm BraceletTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 15677Accepted: 7130DescriptionBessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3...
阅读全文
摘要:BabelfishTime Limit:3000MSMemory Limit:65536KTotal Submissions:26333Accepted:11301DescriptionYou have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to he...
阅读全文
摘要:4 Values whose Sum is 0Time Limit:15000MSMemory Limit:228000KTotal Submissions:12224Accepted:3426Case Time Limit:5000MSDescriptionThe SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a + b
阅读全文
摘要:Sacrament of the sumTime Limit:1000MSMemory Limit:65536KTotal Submissions:1628Accepted:756Description— The Brother of mine, the Head of Monastic Order wants to know tomorrow about the results long-term researches. He wants to see neither more nor less than the Su...
阅读全文

浙公网安备 33010602011771号