原创 hdu 1879 繼續暢通工程————最小生成樹(Kruskal)

省政府“暢通工程”的目標是使全省任何兩個村莊間都可以實現公路交通(但不一定有直接的公路相連,只要能間接通過公路可達即可)。現得到城鎮道路統計表,表中列出了任意兩城鎮間修建道路的費用,以及該道路是否已經修通的狀態。現請你編寫程序,計算出全

原创 hdu 1150 Machine Schedule————匈牙利算法模板題

Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due

原创 hdu 2191 ———— 多重揹包模板題

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

原创 HDU 1503 Advanced Fruits————LCS(最長公共子序列)變形之字符串合併

The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit

原创 POJ 1655 Balancing Act————樹形dp 求樹的重心

Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a forest: a co

原创 POJ 3466 Proud Merchants ———01揹包變形 取物品要有先後順序

Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the w

原创 HUNNU oj 11757 Brackets————區間dp (括號匹配)

We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular bra

原创 HDU 1068 Girls and Boys ———— 匈牙利算法

In the second year of the university somebody started a study on the romantic relations between the students. The relat

原创 HDU 3506 Monkey Party————區間dp + 環形dp + 四邊形優化

Far away from our world, there is a banana forest. And many lovely monkeys live there. One day, SDH(Song Da Hou), who

原创 石子歸併————區間dp模板題

石子歸併:傳送門   N堆石子擺成一條線。現要將石子有次序地合併成一堆。規定每次只能選相鄰的2堆石子合併成新的一堆,並將新的一堆石子數記爲該次合併的代價。計算將N堆石子合併成一堆的最小代價。   例如: 1 2 3 4,有不少合併方法

原创 HDU 1495 非常可樂————BFS 倒水問題

大家一定覺的運動以後喝可樂是一件很愜意的事情,但是seeyou卻不這麼認爲。因爲每次當seeyou買了可樂以後,阿牛就要求和seeyou一起分享這一瓶可樂,而且一定要喝的和seeyou一樣多。但seeyou的手中只有兩個杯子,它們的容量分

原创 HDU N皇后問題————DFS

在N*N的方格棋盤放置了N個皇后,使得它們不相互攻擊(即任意2個皇后不允許處在同一排,同一列,也不允許處在與棋盤邊框成45角的斜線上。 你的任務是,對於給定的N,求出有多少種合法的放置方法。   Input 共有若干行,每行一個正整數N≤

原创 poj 1258 Agri-Net————圖的最小生成樹(Kruskal)

Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all

原创 POJ 3041 Asteroids ———— 匈牙利算法模板題 (最小點覆蓋)

Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500)

原创 POJ 1141 Brackets Sequence——區間dp (括號匹配 + 輸出括號)

Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S i