原创 奇妙的塔

用1,2,...,n表示n個盤子,稱爲1號盤,2號盤,...。號數大盤子就大。經典的漢諾塔問  題經常作爲一個遞歸的經典例題存在。可能有人並不知道漢諾塔問題的典故。漢諾塔來源於  印度傳說的一個故事,上帝創造世界時作了三根金剛石柱子,在一

原创 Red and Black--(BFS)

There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on

原创 Oil Deposits--(DFS)

The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with o

原创 產生冠軍 --(拓撲排序)

有一羣人,打乒乓球比賽,兩兩捉對撕殺,每兩個人之間最多打一場比賽。  球賽的規則如下:  如果A打敗了B,B又打敗了C,而A與C之間沒有進行過比賽,那麼就認定,A一定能打敗C。  如果A打敗了B,B又打敗了C,而且,C又打敗了A,那麼A、

原创 確定比賽名次 --(拓撲排序)

有N個比賽隊(1<=N<=500),編號依次爲1,2,3,。。。。,N進行比賽,比賽結束後,裁判委員會要將所有參賽隊伍從前往後依次排名,但現在裁判委員會不能直接獲得每個隊的比賽成績,只知道每場比賽的結果,即P1贏P2,用P1,P2表示,排

原创 vacations

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following informati

原创 一支獨木

n個人,已知每個人體重。獨木舟承重固定,每隻獨木舟最多坐兩個人,可以坐一個人或者兩個人。顯然要求總重量不超過獨木舟承重,假設每個人體重也不超過獨木舟承重,問最少需要幾隻獨木舟?  Input 第一行包含兩個正整數n (0 接下來n行,每行

原创 Red and Black--(DFS)

There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on

原创 A - A - Stages (水題壓壓驚)

Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of t

原创 蛇行矩陣

題目描述 蛇形矩陣是由1開始的自然數依次排列成的一個矩陣上三角形。 輸入 本題有多組數據,每組數據由一個正整數N組成。(N不大於100) 輸出 對於每一組數據,輸出一個N行的蛇形矩陣。兩組輸出之間不要額外的空行。矩陣三角中同一行的數字用一

原创 Ubiquitous Religions --(並查集)

There are so many different religions in the world today that it is difficult to keep track of them all. You are intere

原创 最大子段和 --(動態規劃)

N個整數組成的序列a11,a22,a33,…,ann, 求該序列如aii+ai+1i+1+…+ajj的連續子段和的最大值。當所給的整數均爲負數時和爲0。 例如:-2,11,-4,13,-5,-2,和最大的子段爲:11,-4,13。和爲20

原创 Number Sequence --(kmp)

Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1

原创 悼念512汶川大地震遇難同胞——珍惜現在,感恩生活 --(多重揹包)

急!災區的食物依然短缺!  爲了挽救災區同胞的生命,心繫災區同胞的CK準備自己採購一些糧食支援災區,現在假設CK一共有資金n元,而市場有m種大米,每種大米都是袋裝產品,其價格不等,並且只能整袋購買。  請問:CK能用有限的資金最多能採購多

原创 Oulipo --(kmp)

The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member