摘要:挖坑...----------------------------一 模板----------------------------const int maxn=1111111;char P[maxn];char T[maxn];int f[maxn];void getFail(char P[],int f[]){ int i=0,j=-1; int len=strlen(P); f[0]=-1; while (i f[n] ] 是最长的子串,既是是s的前缀又是s的后缀,同理1 -> f[ f[n] ] 是次短的...依次递归 while (f[n]>0){...
阅读全文
摘要:--------------------DescriptionThere is a group of adventurers who like to travel in the desert. Everyone knowstravellingin desert can be very dangerous. That's why they plan their trip carefully every time. There are a lot of factors to consider before they make their final decision.One of the
阅读全文
摘要:----------Problem AACM CONTEST AND BLACKOUTIn order to prepare the “The First National ACM School Contest”(in 20??) the major of the city decided to provide all the schools with a reliable source of power. (The major is really afraid of blackoutsJ). So, in order to do that, power station “Future” an
阅读全文
摘要:-----------------Slim SpanTime Limit:5000MSMemory Limit:65536KTotal Submissions:5725Accepted:3008DescriptionGiven an undirected weighted graphG, you should find one of spanning trees specified as follows.The graphGis an ordered pair (V,E), whereVis a set of vertices {v1,v2, …,vn} andEis a set of und
阅读全文
摘要:-----------------------Once again, James Bond is on his way to saving the world. Bond's latest mission requires him to travel between several pairs of cities in a certain country.The country hasNcities (numbered by 1, 2, . . .,N), connected byMbidirectional roads. Bond is going to steal a vehicl
阅读全文
摘要:------------------------------Qin Shi Huang's National Road SystemTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2168Accepted Submission(s): 789Problem DescriptionDuring the Warring States Period of ancient China(476 BC to 221 BC), there were
阅读全文
摘要:Problem AAdventure of Super MarioInput:Standard InputOutput:Standard OutputAfter rescuing the beautiful princess, Super Mario needs to find a way home -- with the princess of course :-) He's very familiar with the 'Super Mario World', so he doesn't need a map, he only needs the best
阅读全文
摘要:Problem CFLYING TO FREDERICTONAfter being inspired by Salvador Dali's artwork, Brett decided he would like to travel to Fredericton, New Brunswick to visit the Beaverbrook Art Gallery.Brett lives in Calgary, and would like to find the cheapest flight or flights that would take him to Fredericton
阅读全文
摘要:------------------------------学习资料------------------------------http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=binaryIndexedTreeshttp://hi.baidu.com/wyl8899/item/c3ac1c0eec3516ea34990267http://hi.baidu.com/solofancy/item/a6b7da6abdea54126995e65fhttp://blog.csdn.net/pkqs90/art
阅读全文
摘要:回文子序列----------------------------最长回文子序列题目略----------------------------这是回文子序列的基础,直接DP即可。f[ L ][ R ] 表示区间[ L , R ] 的最长回文子序列长度。f[ L ][ R ] = 0 ( L > R )f[ L ][ R ] = 1 ( L = R )f[ L ][ R ] = f[ L+1 ][ R-1 ] + 2 ( S[ L ]==S[ R ] )f[ L ][ R ] = max( f[ L+1 ][ R ] , f[ L ][ R-1 ] )-------------------
阅读全文
摘要:Two Rabbits---------------------------------------------------------------------模型可以转化为求长度为n的序列的最长回文子序列方法为枚举起点+记忆化+环形dp用next(i)代替i++,prev(i)代替i--f[i][j]表示环(i,j)的最长回文子序列。若i=j则环区间为空,若i>j则区间为 i i+1 i+2 ... n-1 ... j-2 j-1 j若i#include #include #include #include using namespace std;const int maxn=1111
阅读全文
摘要:-----------------------------A. Xenia and Divisors---将n个数3个一组分成满足条件的n/3组。由于数字最多是7,所以只有124、126、136三种分组方式。先分出所有的136,再分出124,126。若所有数字都用光则分组成功。---#include using namespace std;int n;int a[10]={0};bool check(){ for (int i=1;i>n; for (int i=0;i>t; a[t]++; } if (n%3!=0){ cout0||a[7...
阅读全文
摘要:Good NumbersTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 602Accepted Submission(s): 220Problem DescriptionIf we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.You are required to c
阅读全文
摘要:-------------------------A. Business trip---至少浇几个月水能使花的长度超过k。---#include #include using namespace std;int main(){ int k; int a[13]; int sum=0; int ans=-1; cin>>k; for (int i=0;i>a[i]; } sort(a,a+12,greater()); if (k==0){ cout=k){ ans=i+1; break...
阅读全文
摘要:------------------A. Arrival of the General---可以交换相邻两个数字。求将最大值移到最左边,最小值移到最右边所用的最小步数。---#include using namespace std;int main(){ int n; int a[111]; cin>>n; int mx=0,mi=999; int p1,p2; for (int i=0;i>a[i]; if (a[i]>mx){ mx=a[i]; p1=i; } if (...
阅读全文
摘要:--------------A. Insomnia cure---求1~n中能被klmn整除的数的个数。---#include using namespace std;int main(){ int k,l,m,n,d; cin>>k>>l>>m>>n>>d; int sum=0; for (int i=1;iusing namespace std;const double eps=1e-8;int main() { int vp,vd,t,f,c; cin>>vp>>vd>>t>>f&
阅读全文
摘要:----------------A. Lucky Ticket---判断给出的数字是不是两半和相等的幸运数字。---#include using namespace std;int main(){ int n; char s[111]; cin>>n>>s; bool ok=true; for (int i=0;i#include using namespace std;bool check(int a,int b){ int n=0; int i=1; while (a>0){ int t=a%10; a/=10; ...
阅读全文
摘要:Minimum CutTime Limit:10000MSMemory Limit:65536KTotal Submissions:6869Accepted:2848Case Time Limit:5000MSDescriptionGiven an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must be removed at least to d
阅读全文
摘要:FiringTime Limit:5000MSMemory Limit:131072KTotal Submissions:7126Accepted:2164DescriptionYou’ve finally got mad at “the world’s most stupid” employees of yours and decided to do some firings. You’re now simply too mad to give response to questions like “Don’t you think it is an even more stupid deci
阅读全文
摘要:Transferring SyllaTime Limit:5000MSMemory Limit:65536KTotal Submissions:1320Accepted:322DescriptionAfter recapturing Sylla, the Company plans to establish a new secure system, a transferring net! The new system is designed as follows:The Company staff chooseNcities around the nation which are connec
阅读全文
摘要:7758. Growing StringsProblem code: MGLAR10EnglishVietnameseGene and Gina have a particular kind of farm. Instead of growing animals and vegetables, asit is usually the case in regular farms, they grow strings. A string is a sequence of characters.Strings have the particularity that, as they grow, th
阅读全文
摘要:-----------------------A. Help Vasilisa the Wise 2---暴力枚举---#include using namespace std;int r1,r2,c1,c2,d1,d2;int a[2][2];bool solve(){ if (a[0][0]+a[0][1]!=r1) return false; if (a[1][0]+a[1][1]!=r2) return false; if (a[0][0]+a[1][0]!=c1) return false; if (a[0][1]+a[1][1]!=c2) return fa...
阅读全文
摘要:--------------A. Amusing Joke--前两行的字母恰好组成最后一行--#include #include using namespace std;char a[1111];int ch[26]={0};int main(){ cin>>a; for (int i=0;a[i];i++){ ch[a[i]-'A']++; } cin>>a; for (int i=0;a[i];i++){ ch[a[i]-'A']++; } cin>>a; for (int i=0;a[i];i++){ ...
阅读全文
摘要:Minimizing maximizerTime Limit:5000MSMemory Limit:30000KTotal Submissions:3047Accepted:1187DescriptionThe company Chris Ltd. is preparing a new sorting hardware called Maximizer. Maximizer has n inputs numbered from 1 to n. Each input represents one integer. Maximizer has one output which represents
阅读全文
摘要:BlocksTime Limit:1000MSMemory Limit:65536KTotal Submissions:3665Accepted:1611DescriptionPanda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be
阅读全文
摘要:---/*==============================================*\ | Code Library\*==============================================*//** head-file **/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** define-for **/#define REP(
阅读全文