摘要:Word maker!Time Limit 5000msMemory Limit 65536KdescriptionProbably, you have seen polyhedrons which have an English letter on each face of them. Little Ali has some of these polyhedrons and some words in his mind. We want to know how many of these words can be made by juxtaposing these polyhedrons.
阅读全文
摘要:The Tower of BabylonPerhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story:The babylonians hadntypes of blocks, and an unlimited supply of bloc
阅读全文
摘要:Problem CLongest Run on a SnowboardInput:standard inputOutput:standard outputTime Limit:5 secondsMemory Limit:32 MBMichael likes snowboarding. That's not very surprising, since snowboarding is really great. The bad thing is that in order to gain speed, the area must slide downwards. Another disa
阅读全文
摘要:Return of the AztecsProblem C:Homer SimpsonTime Limit: 3 secondsMemory Limit: 32 MBHomer Simpson, a very smart guy, likes eating Krusty-burgers. It takes Homer m minutes to eat a Krusty- burger. However, there�s a new type of burger in Apu�s Kwik-e-Mart. Homer likes those too. It takes him n minutes
阅读全文
摘要:SuperSaleThere is a SuperSale in a SuperHiperMarket. Every person can take only one object of each kind, i.e. one TV, one carrot, but for extra low price. We are going with a whole family to that SuperHiperMarket. Every person can take as many objects, as he/she can carry out from the SuperSale. We
阅读全文
摘要:Dividing coinsIt's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great length and thus created copper-wire.Not commonly kno
阅读全文
摘要:Let Me Count The WaysAfter making a purchase at a large department store, Mel's change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a convenience store. Again his change was 17 cents. This time he received 2 nickels and 7 pennies. He began to wond
阅读全文
摘要:DollarsNew Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up
阅读全文
摘要:English GameTime Limit 1000msMemory Limit 65536Kdescription This English game is a simple English words connection game. The rules are as follows: there are N English words in a dictionary, and every word has its own weight v. There is a weight if the corresponding word is used. Now there is a ta...
阅读全文
摘要:BMega Man’s MissionsInputStandard InputOutputStandard OutputMega Man is off to save the world again. His objective is to kill the Robots created by Dr. Wily whose motive is to conquer the world. In each mission, he will try to destroy a particular Robot. Initially, Mega Man is equipped with a weapon
阅读全文
摘要:Palindromic SubsequenceA Subsequence is a sequence obtained by deleting zero or more characters in a string. A Palindrome is a string which when read from left to right, reads same as when read from right to left. Given a string, find the longest palindromic subsequence. If there are many answers to
阅读全文
摘要:EmergencyTime Limit 3000msMemory Limit 65536KdescriptionKudo’s real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, and Kudo is only her nickname.
Now, she is facing an emergency in her hometown:
Her mother is developing a new kind of spacecraft. This plan costs enormous energy but
阅读全文
摘要:ClockwiseTime Limit 1000msMemory Limit 65536KdescriptionSaya have a long necklace with N beads, and she signs the beads from 1 to N. Then she fixes them to the wall to show N-1 vectors – vector i starts from bead i and end up with bead i+1.
One day, Kudo comes to Saya’s home, and she sees the beads
阅读全文
摘要:Problem DWavio SequenceInput:Standard InputOutput:Standard OutputTime Limit:2 SecondsWavio is a sequence of integers. It has some interesting properties.·Wavio is of odd length i.e.L = 2*n + 1.·The first(n+1)integers of Wavio sequence makes a strictly increasing sequence.·The last(n+1
阅读全文
摘要:Traveling salesmen ofnhn. (the prestigious Korean internet company) report their current location to the company on a regular basis. They also have to report their new location to the company if they are moving to another location. The company keep each salesman's working path on a map of his wo
阅读全文
摘要:Problem H: Partitioning by PalindromesWe say a sequence of characters is apalindromeif it is the same written forwards and backwards. For example, 'racecar' is a palindrome, but 'fastcar' is not.Apartitionof a sequence of characters is a list of one or more disjoint non-empty groups
阅读全文
摘要:Problem DPrince and PrincessInput:Standard InputOutput:Standard OutputTime Limit:3 SecondsIn ann x nchessboard, Prince and Princess plays a game. The squares in the chessboard are numbered1, 2, 3 ... n*n,as shown below:Prince stands in square1, makepjumps and finally reach squaren*n. He enters a squ
阅读全文
摘要:Let's play a stone removing game.Initially,nstones are arranged on a circle and numbered1,...,nclockwise (Figure 1). You are also given two numberskandm. From this state, remove stones one by one following the rules explained below, until only one remains. In step 1, remove stonem. In step 2, lo
阅读全文
摘要:Problem E: VacationThe ProblemYou are planning to take some rest and to go out on vacation, but you really don't know which cities you should visit. So, you ask your parents for help. Your mother says"My son, you MUST visit Paris, Madrid, Lisboa and London. But it's only fun in this ord
阅读全文
摘要:Question 1: Is Bigger Smarter?The ProblemSome people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ'
阅读全文
摘要:Max Sum of Max-K-sub-sequenceTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4581Accepted Submission(s): 1656Problem DescriptionGiven a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the rig
阅读全文
摘要:FootballTime Limit:1000MSMemory Limit:65536KTotal Submissions:2116Accepted:1055DescriptionConsider a single-elimination football tournament involving 2nteams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Th
阅读全文
摘要:Check the difficulty of problemsTime Limit:2000MSMemory Limit:65536KTotal Submissions:3617Accepted:1580DescriptionOrganizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms:1. All of
阅读全文
摘要:D. Bag of micetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the pri
阅读全文
摘要:LOOPSTime Limit: 15000/5000 MS (Java/Others)Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 830Accepted Submission(s): 342Problem DescriptionAkemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).Homura wants to help her friend Madoka save the world. But because of the plot of the
阅读全文
摘要:Coin ChangeSuppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, two 5-cent coins and one 1-cent coi
阅读全文
摘要:Problem C: Longest Common SubsequenceSequence 1:Sequence 2:Given two sequences of characters, print the length of the longest common subsequence of both sequences. For example, the longest common subsequence of the following two sequences:abcdgh
aedfhr
isadhof length 3.Input consists of pairs of lin
阅读全文
摘要:Juice ExtractorJerry loses himself in the interesting game: Fruit Ninja. Fruit Ninja is a game of iPhone and iPad in which the players cut the fruits coming from the bottom of the screen and gain the bonus from cutting more than two fruits with a single slice. Once a fruit is cut, it breaks into sma
阅读全文
摘要:History GradingBackgroundMany problems in Computer Science involve maximizing some measure according to constraints.Consider a history exam in which students are asked to put several historical events into chronological order. Students who order all the events correctly will receive full credit, but
阅读全文
摘要:UVa专题练习A-410003 经典dp,可用四边形不等式优化UVa 10003 - Cutting Sticks 区间dp10029 基础dp,DAG最长路,需高效构图10032 经典问题。子集和数问题。01背包问题10036 能否在一个整数序列的每相邻两项之间添加一个加减号。使最终结果能被一个定整数K整除10051 简单dp。DAG最长路A-510154 dp中等10163 二分、dp10185 二叉树。dp、贪心A-610239 不错的dp,可优化,解决更大规模的问题10271 经典dp,需要证明一个结论10280 dp、最短路10296 中国油路问题,最短路,任意图最大匹配,用集合dp
阅读全文
摘要:动态规划基础例题LA 3882UVa 3882 - And Then There Was One 递推------------无力orzUVa 1063510635 - Prince and Princess LCS&LISUVa 10891Uva 10891 - Game of Sum dp博弈UVa 11825Uva 11825 - Hackers' Crackdown 状态压缩UVa 10859Uva 10859 - Placing Lampposts 树形dpLA 3983LA 4794简单练习题UVa 11584UVa 11584 - Partitioning by
阅读全文
摘要:Cutting SticksYou have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work requires that they only make one cut at a time.It is easy to notice that different sele
阅读全文
摘要:DNA repairTime Limit: 5000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 872Accepted Submission(s): 473Problem DescriptionBiologists finally invent techniques of repairing DNA that contains segments causing kinds of inherited diseases. For the sake of simplicity,
阅读全文
摘要:Detect the VirusTime Limit:2 Seconds Memory Limit:65536 KBOne day, Nobita found that his computer is extremely slow. After several hours' work, he finally found that it was a virus that made his poor computer slow and the virus was activated by a misoperation of opening an attachment of an email
阅读全文
摘要:Computer Virus on Planet PandoraTime Limit: 6000/2000 MS (Java/Others)Memory Limit: 256000/128000 K (Java/Others)Total Submission(s): 1609Accepted Submission(s): 454Problem DescriptionAliens on planet Pandora also write computer programs like us. Their programs only consist of capital letters (‘A’ t
阅读全文
摘要:Keywords SearchTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23502Accepted Submission(s): 7763Problem DescriptionIn the modern time, Search engine came into the life of everybody like Google, Baidu, etc.Wiskey also wants to bring this feature to
阅读全文
摘要:AC自动机算法AC自动机简介:首先简要介绍一下AC自动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之一。一个常见的例子就是给出n个单词,再给出一段包含m个字符的文章,让你找出有多少个单词在文章里出现过。要搞懂AC自动机,先得有字典树Trie和KMP模式匹配算法的基础知识。KMP算法是单模式串的字符匹配算法,AC自动机是多模式串的字符匹配算法。AC自动机的构造:1.构造一棵Trie,作为AC自动机的搜索数据结构。2.构造fail指针,使当前字符失配时跳转到具有最长公共前后缀的字符继续匹配。如同 KMP算法一样, AC自动机在匹配时如
阅读全文
摘要:AC自动机算法AC自动机简介:首先简要介绍一下AC自动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之一。一个常见的例子就是给出n个单词,再给出一段包含m个字符的文章,让你找出有多少个单词在文章里出现过。要搞懂AC自动机,先得有字典树Trie和KMP模式匹配算法的基础知识。KMP算法是单模式串的字符匹配算法,AC自动机是多模式串的字符匹配算法。AC自动机的构造:1.构造一棵Trie,作为AC自动机的搜索数据结构。2.构造fail指针,使当前字符失配时跳转到具有最长公共前后缀的字符继续匹配。如同 KMP算法一样, AC自动机在匹配时如
阅读全文
摘要:每个节点只访问一次。//子树节点是在插入时new的,
//寻找失配指针中使用的队列是直接调用STL的
const int kind = 26;
struct node
{ node *fail; node *next[kind]; int count;//记录当前前缀是完整单词出现的个数 node() { fail = NULL; count = 0; memset(next,NULL,sizeof(next)); }
}; void insert(char *str,node *root)
{
...
阅读全文
摘要:Magic TreeTime Limit 1000msMemory Limit 65536Kdescription Every acmer dream for gold medal. Fotunately,there are two magic trees (which are conveniently numbered 1 and 2) in our campus, each full of gold medal. The trees are very high, so we can not touch the gold medal when they are in the tree bu.
阅读全文
摘要:TripTime Limit 1000msMemory Limit 65536Kdescription Xiao wang has a new car, so he wants to have a trip from his home to hefei, however, there is no road from his house directly to Hefei, so he has to go through a number of cities to get to hefei, his car takes one unit of time driving a unit dista.
阅读全文
摘要:Reverse a RoadTime Limit 1000msMemory Limit 65536Kdescription Peter resides in the city of Nanuh, and goes to his working place in this city every weekday.He has been totally annoyed with the road traffic of this city. All the roads in this city are one-way, so he has to drive a longer way than he .
阅读全文
摘要:#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; int f[1111111]; void getfail(char* P,int *f)
{ int m=strlen(P); f[0]=f[1]=0; for (int i=1;i<m;i++) { int j=f[i]; while (j&&P[i]!=P[j]) j=f[j]; f[i+1]=(P[i]==P[j])?j+1:0; }
} ...
阅读全文
摘要:For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 ≤ i ≤ N) we want to know the largest K > 1 (if there is one) such that the prefix of S with lengt
阅读全文
摘要:Neal is very curious about combinatorial problems, and now here comes a problem about words. Knowing that Ray has a photographic memory and this may not trouble him, Neal gives it to Jiejie.Since Jiejie can't remember numbers clearly, he just uses sticks to help himself. Allowing for Jiejie'
阅读全文
摘要:Minimum Inversion NumberTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6365Accepted Submission(s): 3875Problem DescriptionThe inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai
阅读全文
摘要:E. Subsegmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProgrammer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in, which Sasha coped with.
阅读全文
摘要:D. Dottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a
阅读全文
摘要:A Simple Problem with IntegersTime Limit:5000MSMemory Limit:131072KTotal Submissions:41899Accepted:12169Case Time Limit:2000MSDescriptionYou haveNintegers,A1,A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interv
阅读全文
摘要:Just a HookTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11297Accepted Submission(s): 5591Problem DescriptionIn the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecu
阅读全文
摘要:I Hate ItTime Limit: 9000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 23163Accepted Submission(s): 9257Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个
阅读全文
摘要:敌兵布阵Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25659Accepted Submission(s): 11092Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人
阅读全文
摘要:PartyTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2822Accepted Submission(s): 878Problem Description有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席。在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在聚会上的。有没有可能会有n 个人同时列席?Inputn: 表示有n对夫妻被邀请 (n<= 1000)m: 表示
阅读全文
摘要:#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn=4444;
const int maxm=1111111; struct EDGE{ int to; int w; int next;
}edges[maxm]; int head[maxn];
int edge,node; int lowlink[maxn],pre[maxn],sccno[maxn],stk[maxn],top,dfs_clock,scc_cnt; voi
阅读全文
摘要://-----Kosaraju vector<int>G[maxn],G2[maxn];
vector<int>S;
int vis[maxn],sccno[maxn],scc_cnt; void dfs1(int u)
{ if (vis[u]) return; vis[u]=1; for (int i=0;i<G[u].size();i++) dfs1(G[u][i]); S.push_back(u);
} void dfs2(int u)
{ if (sccno[u]) return; sccno[u]=scc_cnt; fo...
阅读全文
摘要:Proving EquivalencesTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1641Accepted Submission(s): 619Problem DescriptionConsider the following exercise, found in a generic linear algebra textbook.Let A be an n × n matrix. Prove that the followin
阅读全文
摘要:#include <iostream>
#include <vector>
#include <stack>
#include <cstring>
#include <cstdio> using namespace std; const int maxn=41111; //-----Tarjan vector<int> G[maxn];
int pre[maxn],lowlink[maxn],sccno[maxn],dfs_clock,scc_cnt;
stack<int> S; void dfs(int u)
阅读全文
摘要://用类,或者结构体定义都行
class trie
{
public: trie* next[26]; int num; int value; trie() { for(int i=0;i<26;i++) next[i]=0; value=0;//记录是不是一个单词 num=0;//记录单词出现的次数 }
}root;
//插入:
void insert(trie* p,char* s)
{ p=&root; int k=0; while(s[k]!='\0') ...
阅读全文
摘要:Remmarguts' DateTime Limit:4000MSMemory Limit:65536KTotal Submissions:17094Accepted:4694Description"Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story."Prince Remmarguts lives i
阅读全文
摘要:在学习算法的过程中,我们除了要了解某个算法的基本原理、实现方式,更重要的一个环节是利用big-O理论来分析算法的复杂度。在时间复杂度和空间复杂度之间,我们又会更注重时间复杂度。时间复杂度按优劣排差不多集中在:O(1), O(log n), O(n), O(n log n), O(n2), O(nk), O(2n)到目前位置,似乎我学到的算法中,时间复杂度是O(log n),好像就数二分查找法,其他的诸如排序算法都是 O(n log n)或者O(n2)。但是也正是因为有二分的 O(log n), 才让很多 O(n2)缩减到只要O(n log n)。关于二分查找法二分查找法主要是解决在“一堆数中找
阅读全文
摘要:Doctor NiGONiGO’s multi-core CPUTime Limit 2000msMemory Limit 65536KdescriptionDoctor NiGONiGO has developed a new kind of multi-core CPU, it works as follow. There are q (1 < q ≤ 50) identical cores in the CPU, and there are p (0 < p ≤ 200) jobs need to be done. Each job should run in some co
阅读全文
摘要:最长k可重区间集问题Time Limit 1000msMemory Limit 65536Kdescription 给定实直线L 上n 个开区间组成的集合I,和一个正整数k,试设计一个算法,从开区间集合I 中选取出开区间集合S属于I,使得在实直线L 的任何一点x,S 中包含点x 的开区间个数不超过k,且 达到最大。这样的集合S称为开区间集合I的最长k可重区间集。称为最长k可重区间集的长度。 对于给定的开区间集合I和正整数k,计算开区间集合I的最长k可重区间集的长度。 input多组数据输入.
每组输入第1 行有2 个正整数n和k,分别表示开区间的个数和开区间的可重...
阅读全文
摘要:深海机器人问题Time Limit 1000msMemory Limit 65536Kdescription 深海资源考察探险队的潜艇将到达深海的海底进行科学考察。潜艇内有多个深海机器人。潜艇到达深海海底后,深海机器人将离开潜艇向预定目标移动。深海机器人在移动中还必须沿途采集海底生物标本。沿途生物标本由最先遇到它的深海机器人完成采集。每条预定路径上的生物标本的价值是已知的,而且生物标本只能被采集一次。本题限定深海机器人只能从其出发位置沿着向北或向东的方向移动,而且多个深海机器人可以在同一时间占据同一
位置。 用一个P′Q 网格表示深海机器人的可移动位置。西南角的坐标为(0,0),...
阅读全文
摘要:负载平衡问题Time Limit 1000msMemory Limit 65536Kdescription G 公司有n 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等。如何用最少搬运量可以使n 个仓库的库存数量相同。搬运货物时,只能在相邻的仓库之间搬运。 对于给定的n 个环形排列的仓库的库存量,编程计算使n 个仓库的库存数量相同的最少搬运量。 input多组数据输入.
每组输入第1 行中有1 个正整数n(n<=100),表示有n个仓库。第2 行中有n个正整数,表示n个仓库的库存量。 output每组输出最少搬运量 sam...
阅读全文
摘要:运输问题Time Limit 1000msMemory Limit 65536Kdescription W公司有m个仓库和n 个零售商店。第i 个仓库有ai 个单位的货物;第j 个零售商店需要bj个单位的货物。货物供需平衡,即。从第i 个仓库运送每单位货物到第j 个零售商店的费用为Cij 。试设计一个将仓库中所有货物运送到零售商店的运输方案,使总运输费用最少。 对于给定的m 个仓库和n 个零售商店间运送货物的费用,计算最优运输方案和最差运输方案。 input多组数据输入.
每组输入第1行有2 个正整数m和n,分别表示仓库数和零售商店数。接下来的一行中有m个正整数a...
阅读全文
摘要:最长递增子序列问题Time Limit 1000msMemory Limit 65536Kdescription给定正整数序列x1 , ... , xn 。
(1)计算其最长递增子序列的长度s。
(2)计算从给定的序列中最多可取出多少个长度为s的递增子序列。
(3)如果允许在取出的序列中多次使用x1和xn,则从给定序列中最多可取出多少个长度为s的递增子序列。
设计有效算法完成(1)(2)(3)提出的计算任务。 input多组数据输入.
每组输入第1 行有1个正整数n,表示给定序列的长度。接下来的1 行有n个正整数x1 ,... , xn。 output每组输出第...
阅读全文
摘要:数字梯形问题Time Limit 1000msMemory Limit 65536Kdescription 给定一个由n 行数字组成的数字梯形如下图所示。梯形的第一行有m 个数字。从梯形的顶部的m 个数字开始,在每个数字处可以沿左下或右下方向移动,形成一条从梯形的顶至底的路径。
规则1:从梯形的顶至底的m条路径互不相交。
规则2:从梯形的顶至底的m条路径仅在数字结点处相交。
规则3:从梯形的顶至底的m条路径允许在数字结点相交或边相交。 2 3 3 4 5 9...
阅读全文
摘要:餐巾计划问题Time Limit 2000msMemory Limit 65536Kdescription 一个餐厅在相继的N 天里,每天需用的餐巾数不尽相同。假设第i天需要ri块餐巾(i=1,2,…,N)。餐厅可以购买新的餐巾,每块餐巾的费用为p分;或者把旧餐巾送到快洗部,洗一块需m天,其费用为f 分;或者送到慢洗部,洗一块需n 天(n > m),其费用为s < f 分。每天结束时,餐厅必须决定将多少块脏的餐巾送到快洗部,多少块餐巾送到慢洗部,以及多少块保存起来延期送洗。但是每天洗好的餐巾和购买的新餐巾数之和,要满足当天的需求量。
试设计一个算法为餐厅合理地安排好N 天中餐巾使用
阅读全文
摘要:C. Sequence of Ballstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of ballsAby your teacher, each labeled with a lowercase Latin letter 'a'-'z'. You don't like the given sequence. You want to change it
阅读全文
摘要:飞行员配对方案问题Time Limit 1000msMemory Limit 65536Kdescription 第二次世界大战时期,英国皇家空军从沦陷国征募了大量外籍飞行员。由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2 名飞行员,其中1 名是英国飞行员,另1 名是外籍飞行员。在众多的飞行员中,每一名外籍飞行员都可以与其他若干名英国飞行员很好地配合。如何选择配对飞行的飞行员才能使一次派出最多的飞机。对于给定的外籍飞行员与英国飞行员的配合情况,试设计一个算法找出最佳飞行员配对方案,使皇家空军一次能派出最多的飞机。 对于给定的外籍飞行员与英国飞行员的配合情况,...
阅读全文
摘要:编号问题名称问题模型转化模型1飞行员配对方案问题二分图最大匹配网络最大流2太空飞行计划问题最大权闭合图网络最小割3最小路径覆盖问题有向无环图最小路径覆盖网络最大流4魔术球问题有向无环图最小路径覆盖网络最大流5圆桌问题二分图多重匹配网络最大流6最长递增子序列问题最多不相交路径网络最大流7试题库问题二分图多重匹配网络最大流8机器人路径规划问题(未解决)最小费用最大流9方格取数问题二分图点权最大独立集网络最小割10餐巾计划问题线性规划网络优化最小费用最大流11航空路线问题最长不相交路径最小费用最大流12软件补丁问题最小转移代价最短路径13星际转移问题网络判定网络最大流14孤岛营救问题分层图最短路径最
阅读全文
摘要:分配问题Time Limit 1000msMemory Limit 65536Kdescription 有n件工作要分配给n个人做。第i 个人做第j 件工作产生的效益为ij c 。试设计一个将n件工作分配给n个人做的分配方案,使产生的总效益最大。 对于给定的n件工作和n个人,计算最优分配方案和最差分配方案。 input多组数据输入.
每组输入第1 行有1 个正整数n<=50,表示有n件工作要分配给n 个人做。接下来的n 行中,每行有n 个整数Cij,1≤i≤n,1≤j≤n,表示第i 个人做第j件工作产生的效益为Cij 。 output每组输出的最小...
阅读全文
摘要:新的模板#include <iostream>
#include <cstdio> using namespace std; const int OO=1e9;//无穷大
const int maxm=1111111;//边的最大数量,为原图的两倍
const int maxn=2222;//点的最大数量 int node,src,dest,edge;//node节点数,src源点,dest汇点,edge边数
int head[maxn],p[maxn],dis[maxn],q[maxn],vis[maxn];//head链表头,p记录可行流上节点对应的反向边,dis计
阅读全文
摘要:最小路径覆盖问题Time Limit 1000msMemory Limit 65536Kdescription 给定有向图G=(V,E)。设P 是G 的一个简单路(顶点不相交)的集合。如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖。P 中路径可以从V 的任何一个顶点开始,长度也是任意的,特别地,可以为0。G 的最小路径覆盖是G 的所含路径条数最少
的路径覆盖。
设计一个有效算法求一个有向无环图G 的最小路径覆盖。
提示:设V={1,2,...; ,n},构造网络G1=(V1,E1)如下: 每条边的容量均为1。求网络G1的(x0 , y0 )最大流。
对于给定的给定有...
阅读全文
摘要:E. Petya and Posttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle wor
阅读全文
摘要:方格取数问题Time Limit 1000msMemory Limit 65536Kdescription 在一个有m*n 个方格的棋盘中,每个方格中有一个正整数。现要从方格中取数,使任意2 个数所在方格没有公共边,且取出的数的总和最大。试设计一个满足要求的取数算法。
对于给定的方格棋盘,按照取数要求编程找出总和最大的数。 input多组数据输入.
每组输入第1 行有2 个正整数m和n,分别表示棋盘的行数和列数。接下来的m行,每行有n个正整数,表示棋盘方格中的数。 output每组输出取数的最大总和. sample_input3 3
1 2 ...
阅读全文
摘要:太空飞行计划问题Time Limit 1000msMemory Limit 65536Kdescription W教授正在为国家航天中心计划一系列的太空飞行。每次太空飞行可进行一系列商业性实验而获取利润。现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的全部仪器的集合I={I1,I2,…In}。实验Ej需要用到的仪器是I的子集。配置仪器Ik的费用为ck美元。实验Ej的赞助商已同意为该实验结果支付pj美元。W教授的任务是找出一个有效算法,确定在一次太空飞行中要进行哪些实验并因此而配置哪些仪器才能使太空飞行的净收益最大。这里净收益是指进行实验所获得的全部收...
阅读全文
摘要:The Perfect StallHal BurchTime Limit 1000msMemory Limit 65536KdescriptionFarmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are different. For the first week, Farmer John rando
阅读全文
摘要:Drainage DitchesHal BurchTime Limit 1000msMemory Limit 65536KdescriptionEvery time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built
阅读全文
摘要:#include <iostream> using namespace std; const int OO=1e9;//无穷大
const int maxm=111111;//边的最大数量,为原图的两倍
const int maxn=999;//点的最大数量 int node,src,dest,edge;//node节点数,src源点,dest汇点,edge边数
int head[maxn],work[maxn],dis[maxn],q[maxn];//head链表头,work临时表头,dis计算距离 struct edgenode{ int to;//边的指向 int...
阅读全文
摘要:Ford-Fulkson的具体步骤1、初始化网络中所有边的容量,c<u,v>继承该边的容量,c<v,u>初始化为0,其中边<v,u>即为回退边。初始化最大流为0。2、在残留网络中找一条从源S到汇T的增广路p。如能找到,则转步骤3,;如不能找到,则转步骤5。3、在增广路p中找到所谓的"瓶颈"边,即路径中容量最小的边,记录下这个值X,并且累加到最大流中,转步骤4。4、将增广路中所有c<u,v>减去X,所有c<v,u>加上X,构成新的残留网络。转步骤2。5、得到网络的最大流,退出。Edmond-Karp算法用朴素的BFS
阅读全文
摘要:C. Partytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA company hasnemployees numbered from1ton. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employeeAis sai
阅读全文
摘要:C. Learning Languagestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe "BerCorp" company has gotnemployees. These employees can usemapproved official languages for the formal correspondence. The languages are numbered with integers fr
阅读全文
摘要:D. Subwaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA subway scheme, classic for all Berland cities is represented by a set ofnstations connected bynpassages, each of which connects exactly two stations and does not pass through any others.
阅读全文
摘要:D. Colorful Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an undirected graph, consisting ofnvertices andmedges. We will consider the graph's vertices numbered with integers from 1 ton. Each vertex of the graph has a col
阅读全文
摘要:A. Ice Skatingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he land
阅读全文
摘要:A. Ring roadtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Fo
阅读全文
摘要:B. Cthulhutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other en
阅读全文
摘要:D. Cycle in Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a undirected graphG, consisting ofnnodes. We will consider the nodes of the graph indexed by integers from 1 ton. We know that each node of graphGis connected by edge
阅读全文
摘要:A. Dorm Water Supplytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe German University in Cairo (GUC) dorm houses are numbered from1ton. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow onl
阅读全文
摘要:D. Road Maptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere arencities in Berland. Each city has its index — an integer number from1ton. The capital has indexr1. All the roads in Berland are two-way. The road system is such that there is exa
阅读全文
摘要:D. Missile Silostime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA country called Berland consists ofncities, numbered with integer numbers from1ton. Some of them are connected by bidirectional roads. Each road has some length. There is a path fro
阅读全文
摘要:C. Cycletime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAtournamentis a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexesuandv(u ≠ v) exists either an edge
阅读全文
摘要:D. Roads not only in Berlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighbor
阅读全文
摘要:D. Eternal Victorytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to m
阅读全文
摘要:B. pSorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne dayncells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from1). Also each cell determined it
阅读全文
摘要:void dijkstra(int n,int dist[],EDGE edges[],int pre[],int src,int dest)
{ int _min,u,v,w; bool visit[maxn]={0}; for (int i=1;i<=n;i++) { dist[i]=OO; } dist[src]=0; for (int loop=1; loop<=n; loop++) { u=0; _min=OO; for (int i=1; i<=n; i+...
阅读全文
摘要:D. Harry Potter and the Sorting Hattime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The
阅读全文
摘要:touring computeTime Limit 1000msMemory Limit 65536KdescriptionThe best friends Mr. Li and Mr. Liu are touring in beautiful country M. M has n cities and m two-way roads in total. Each road connects two cities with fixed length.We assume that the cost of car traveling on the road is only related ...
阅读全文
摘要:monkeyTime Limit 1000msMemory Limit 65536Kdescription Cc is a lovely monkey. It likes to play the game "catching plates". The game is as follows. There are n pegs in a line numbered from 1 to n. Cc stands on the first peg at the beginning. It is rather hard for Cc to jump from peg i to peg
阅读全文
摘要:素数树Time Limit 1000msMemory Limit 65536KdescriptionSuppose there is a tree named A. All nodes of A have a weight v(0 < v < 4000000).Now, we will give the definition of "Prime Node".A node is a Prime Node if the following conditions are satisfied.The subtree of A whose root node is b w
阅读全文