poj 1958 Strange Towers of Hanoi (dp)

http://poj.org/problem?id=1958做的第一個題目給演算法的題。過程說的很明了,先把n-k個用四個柱子的方法移動到B,再把k個用三個柱子的方法移動到D,最後把n-k個用四個柱子的方法移動到D。n-k個共移動了兩次,三個柱子移動的最少步數我們知道為2^n-1,總的移動步數即為f[i-j]*2+t[j],得轉移方程f[i] = Min(f[i],

poj 1606 Jugs (bfs)

http://poj.org/problem?id=1606猛一看沒思路,仔細想想,記住當前a,b水量及操作就可以bfs了,純粹的暴力啊。。輸出需要路徑,要在node中用指標記錄目前狀態的前一狀態,根據oper輸出即可。code:#include<cstdio>#include<cstring>int a, b, n, h, r ;bool vis[1001][1001] ;int ans[100001] ;struct node{    int va, vb, oper

fzu 1894 志願者選拔 (單調隊列)

http://acm.fzu.edu.cn/problem.php?pid=1894簡單單調隊列。code:#include<cstdio>int data[1000001] ;int queue[1000001] ;int num[1000001] ;int h, r, n ;void insert(){    if(r==h-1||data[n]<queue[r]){        r ++ ;        queue[r] = data[n] ;        num[

poj 2823 Sliding Window (單調隊列)

http://poj.org/problem?id=2823純粹的單調隊列練習題,用了一下輸入的加速,結果發現還不如scanf快...話說前段時間搞單調最佳化的時候,就是有點卡在單調隊列上了,當時真沒整明白資料裡說的到底在維護什麼...今天費老傳了DP資料(完整版...)才算真搞懂。唉,浪費了那麼多激情... 為DP的單調最佳化做準備吧,明天開始搞DP了,不能再縮了... code: #include<cstdio>int data[1000005] ;int queue[10000

poj 2912 Rochambeau (並查集+枚舉)

http://poj.org/problem?id=2912枚舉+關係並查集,並查集與1182相似,枚舉每個小孩為judge時的情況,若當前枚舉情況下每個round都是正確的,則當前枚舉編號可能是judge。若只找到一個judge的可能,則找出排除其他編號所需最多的round數,兩者即為輸出。做了一整天,WA了9次,原因是位移量r公式搞錯一個地方,列了好多次表才搞定。code:#include<cstdio>#include<cstring>using namespace

poj 1182 食物鏈 (並查集)

http://poj.org/problem?id=1182重點依舊是用rank記錄相對於根節點的關係,並及時跟新rank的值。code:#include<cstdio>using namespace std ;int f[50001] ;int r[50001] ;//與根節點的關係int find_Set(int x){    int temp ;    if(x==f[x])        return x ;    temp = f[x] ;    f[x] = find_S

poj 3600 Subimage Recognition (枚舉+dfs)

http://poj.org/problem?id=3600枚舉subimage第一行在image中的位置,然後在image中選取c列,若這c列中有r行和subimage相同,那麼即為有解。code:#include<cstdio>#include<cstring>#include<iostream>using namespace std ;int vis[21] ;char smap[21][21], imap[21][21] ;int r, c, R, C

poj 2503 Babelfish (trie)

http://poj.org/problem?id=2503思路很簡單,對foreign language word建trie樹,插入時一併傳入word的序號,與english word相對應。尋找時直接尋找word標記的序號,從儲存數組中輸出englishword就好了。比較蛋疼的是這題的輸入,一開始真心搞不定啊。。搞定後直接1Y。code:#include<cstdio>#include<cstring>char str[100001][11] ;//模式串char 

poj 1222 & zoj 1354 EXTENDED LIGHTS OUT (枚舉)

http://poj.org/problem?id=1222和poj 1753類似,1753是求全0或全1的步數,這題是求全0的解決方案。當時是拿1753的代碼改的,枚舉步數,最多30步,這樣的話狀態總量就是2^30。。。枚舉第一行狀態,共2^6,第一行確定了便可確定其餘行,最後看末行是否全為0即可。code:#include<cstdio>#include<cstring>int map[5][6], ans[5][6] ;int tur[5][2] = {0, 0, 

zoj 2972 Hurdles of 110m (DP)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2972i為當前第幾段,j為跑完第i段剩餘的體力。第i段有三種跑法可選: 第一種要消耗f1的體力,所以保證j+f1<=m。dp[i][j] = min(dp[i][j], dp[i-1][j+f1]+t1) ;第二種不消耗體力。 dp[i][j] = min(dp[i][j], dp[i-1][j]+t2) ;第三種增加f2的體力,保證j-f2>=0。dp[i][

poj 2236 Wireless Network (並查集)

http://poj.org/problem?id=2236給定N個壞掉的無線發射器座標,給定其能相連通的最大距離,O i 代表修好第i個發射器,S i j 表示判斷第i個和第j個是否能接通(可間接相連)。簡單並查集應用,一個bool數組標記是否可用,每修好一個,找N個中已修好且可以直接相連的合并。最後判斷i,j

poj 3294 Life Forms (尾碼數組)

http://poj.org/problem?id=3294   

poj 3411 Paid Roads (dfs)

http://poj.org/problem?id=3411這題RE了N多次,到最後也不知道是什麼原因。看到網上說vis[x]不會超過3,就試著加上了<=3的限制,我了個去,馬上AC!問題應該還是遞迴過程爆棧了吧。code:#include<cstdio>#include<cstring>const int MAX = 99999999 ;int vis[15] ;int ans, n, m ;bool flag ;struct node{    int a ;  

zoj 1089 Lotto

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1089遞迴實現的排列組合。code:#include<cstdio>int data[20] ;int ans[6], n ;void work(int diex, int aiex){    int i ;    if(aiex==6){        for(i=0; i<5; i++)            printf("%d ", ans[i])

poj 1655 Balancing Act (樹形dfs)

http://poj.org/problem?id=1655同poj3107,只要求輸出一個數值最小的點。剛開始的答案值修改的num[]記錄的,罪過罪過。。。 code:#include<cstdio>#include<cstring>#define Max(a, b)   a>b?a:busing namespace std ;const int MAX = 20001 ;int k, n, Min, anspoint, ansnum ;int vis[MAX],

poj 1260 pearls (dp)

http://poj.org/problem?id=1260很明顯的,當vi<vj<vk且i可以用j來代替(即(si+10)*vi<si*vj)時,則當前解為最優解(因為si*vj<si*vk - -...)。用dp[j]表示前j種pearl的最小代價,i>j&i=1...n,dp[1]=(s1+10)*v1,用第i種pearl替代前i-j種,得狀態轉移方程:dp[i] = min(dp[j] + (sum[i]-sum[j]+10)*val[i])

poj 1984 Navigation Nightmare (並查集)

http://poj.org/problem?id=1984    題目描述的如此蛋疼。。。   

poj 1159 palindrome (dp)

http://poj.org/problem?id=1159卡記憶體的題比卡時間的題還要噁心!用int類型提交就MLE,只能換成short int,65128K,Memory

poj 3107 Godfather (樹形dfs)

http://poj.org/problem?id=3107 給定一棵樹,取去掉某一節點後形成子樹的最大節點數,求使這個數最小的節點。去掉某一節點後,形成的樹包括子樹和原樹去掉以這個點為根的樹所形成的樹,在這幾個樹中求最大值即可。節點數的計算可用回溯,過程中選取最大值。貌似是我第一個用鄰接表存邊的題,貼下模板。鄰接表存邊code:#include<iostream>#include<cstring>#include<cstdio>using namespace

poj 2157 Maze (bfs)

http://poj.org/problem?id=2157算是細節比較多的搜尋題了吧,考慮的時間比較長,最終代碼寫的也是那麼的糾結。。。去真的不知道為什麼RE啊!重新敲了一遍,完全一樣的思路,然後就A掉了!搞毛啊?!白白浪費一下午找bug啊...#include<cstdio>#include<cstring>int key[6], temkey[6] ;int tur[4][2] = {0, 1, 0, -1, 1, 0, -1, 0} ;bool vis[21][2

總頁數: 61357 1 .... 9736 9737 9738 9739 9740 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.