Time of Update: 2018-12-06
http://poj.org/problem?id=1252先計算6種錢幣相加的情況,有f[j] = min(f[j], f[j-data[i]]+1) ;然後計算找零的情況,有f[j] = min(f[j], f[j+data[i]]+1)
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=1850Nim博弈,求保證先手必勝可選的方案數。對於一個必勝的局面,至少有一個方案可以到達必敗局面。也就是說,對於a1^a2..^an!=0一定有一個ai可以改為ai',且a1^a2..^ai'..^an==0。設a1^a2..^an=k,則一定存在某個ai,它的二進位表示在k的最高位上是1(因為k的最高位為1),那麼有ai^k<ai成立。則a1^a2..^an^k=0,可得ai'=ai^k。題意找有多少種
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2971開始想用map的索引值對來做,想想發現沒必要,直接類比就可以了。用一個數組打出0—20和30,40..90等數的英文,輸入時進行匹配,匹配成功便通過它們與下標之間的關係確定。輸入為million,hundred,thousand時,當前值要乘相應10^n。用三個數n1, n2, n3分別記錄每三位元,最後相加即可。code:#include<cstdio>
Time of Update: 2018-12-06
http://poj.org/problem?id=1562水題。code:#include<cstdio>#include<cstring>int tur[8][2] = {-1, -1, -1, 0, -1, 1, 1, -1, 1, 0, 1, 1, 0, 1, 0, -1} ;char map[101][101] ;int n, m, ans, num ;bool vis[101][101] ;struct node{ int x, y ;}coor[100
Time of Update: 2018-12-06
http://poj.org/problem?id=2907挺簡單的一題,但是上來就給想錯了。應該是按各個可用點搜尋,累加各點間距離取最小,我想的是按座標全搜,標記過程值。code:#include<cstdio>#include<cstring>using namespace std ;const int MAX = 1e8 ;int n, m, sx, sy, num, ans ;struct node{ int x, y ; bool vis ;}bee
Time of Update: 2018-12-06
http://poj.org/problem?id=2392背包沒有容量,對於每種木塊,其能達到的最大高度a便可做為其容量。先用二進位最佳化減少數量,然後根據a的值排序,01背包時可以以每種木塊可達到的最大高度為最大容量。RE一次,因為val的大小隻開了401...這裡是個易錯點啊,二進位最佳化後的數量不確定。代碼:#include<cstdio>#include<cstring>#include<cstdlib>#define Max(a, b) a&g
Time of Update: 2018-12-06
http://poj.org/problem?id=1276有一個Cash Machine,裡面裝有t種面值為n[i]的貨幣,每種有v[i]張。問在所換金額不超過cash元錢的情況下,所能換取的最大金額。 多重背包,轉換成01背包來做,其中要用到二進位最佳化。《背包九講》上講的挺不錯,在每件物品價值前加上係數,並保證這些係數的組合包括1..n的所有數且總和為n。代碼:#include<cstdio>#include<cstring>#define Max(a, b)
Time of Update: 2018-12-06
http://www.bianchengla.com/practise/problem?id=1387第一道尾碼數組,求出最大的height值即可。更多的是當個模板用吧。code:#include<cstdio>//最長重複子串#include<cstring>const int maxn = 10001 ;int wa[maxn], wb[maxn], wv[maxn], ws[maxn], rank[maxn], height[maxn], sa[maxn], s[m
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3332看XSY部落格有這題,就做一下,結果夠讓人鬱悶的,太粗心了...一開始用的宏比較多,出了個沒見過的錯 Segmentation Fault
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=2686 多進程DP,昨天第一次聽說...題目大意是找兩條從(1, 1) 到(n, n)的路徑,使權值和最大且節點不重疊。讓兩個進程同時進行,枚舉步數K,當x1==x2||y1==y2時跳過,得狀態轉移方程:dp(k, x1, y1, x2, y2) = max(dp(k-1, x1-1, y1, x2-1, y2), dp(k-1, x1-1, y1, x2, y2-1), dp(k-1, x1, y1-1,
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=2899簡單二分,但這個不滿足單調性。題目要求極值點,以函數導數的正負作為條件二分即可。 code:#include<cstdio>#include<cmath>double y = 0 ;double cal(double x){ return 42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x - y ;}double
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=2199簡單二分尋找,應該屬於水題了吧...糾結的是範例沒過,一試竟然AC。這兩天狀態太差了,發生這麼多事,有點不知所措的感覺。現在都過去了,感覺還是挺煩燥...只能從頭加深下搜尋了。 code:#include<iostream>#include<cstdio>#include<cmath>#include<iomanip>using namespace std
Time of Update: 2018-12-06
http://poj.org/problem?id=3461基礎KMP, 要注意一次尋找完成後,到下一可尋找處繼續匹配,這樣才能保證得到最終個數。 code:#include<cstdio>#include<cstring>char substr[10001] ;char str[1000001] ;int next[10001] ;int sublen, len, ans ;void get_next(){ next[1] = 0 ; int j = 0 ;
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=3507斜率最佳化的DP,完全是看資料做出來的。下面給出資料中對兩個結論的證明: 對基本公式f[i]=min{f[j]+(s[i]-s[j])^2+M},取i的兩個一般決策點j,k(j<k),s[i]為1..i的cost總和,因為cost非負,所以s隨i不減。 若k優於j,則f[k]+(s[i]-s[k])^2+M<f[j]+(s[i]-s[j])^2+M,化簡得f[k]-f[j]+s[k]^2-s[
Time of Update: 2018-12-06
http://poj.org/problem?id=2752KMP的next數組應用。一句話,next[j]必須為滿足str[1..next[j]] = str[j-next[j]+1..j]的最大值。 以abababa為例,next[7] = 5,則 str[1..5] = str[3..7],顯然str[3..5] = str[5..7]。 next[5] = 3,則 str[1..3] = str[3..5],根據上面所得可知str[1..3] =
Time of Update: 2018-12-06
poj2406http://poj.org/problem?id=2406給定一個字串,問最多是多少個相同子串不重疊串連構成。 KMP的next數組應用。這裡主要是如何判斷是否有這樣的子串,和子串的個數。next數組的作用是在匹配無法進行下去時,可繼續匹配的位置。這就要求next[j]必須為滿足str[1..next[j]] = str[j-next[j]+1..j]的最大值。對於串的每一個首碼都取滿足條件的最大值,則next[len]的值即為前一個子串的尾位置。例如ababab,next[4]
Time of Update: 2018-12-06
題意: 給定三個字串,判斷前兩個經過字元順序不變的組合能否變為第三個字串。 用bool型數組dp[i][j]記錄str1的前i個字元和str2的前j個字元能否組合成str3的前i+j個字元。str3的最後一個字元肯定是
Time of Update: 2018-12-06
A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile called the CATCHER which is capable of intercepting multiple incoming offensive missiles. The CATCHER is supposed to
Time of Update: 2018-12-06
http://poj.org/problem?id=2965 16個位置分別有兩個狀態,用一個16位的二進位表示,對beg按位或運算得到初始狀態,bfs中,用只包含0,1的16進位數實現翻轉操作。剩下的就是單純的bfs了。code:#include<iostream>#include<cstdio>#include<cstring>using namespace std ;int dir[16]={0x111f, 0x222f, 0x444f, 0x888f,
Time of Update: 2018-12-06
http://poj.org/problem?id=3280對字串進行增刪操作使其形成迴文串,每次操作都有其對應的花費,求最小花費。典型DP,dp[i][j]為使str[j, i]形成迴文的最小花費。若str[j]==str[i],則dp[i][j]由dp[i-1][j+1]而來。若str[j]!=str[i],則dp[i][j]=min(dp[i-1][j]+v[data[i]], dp[i][j+1]+v[data[j]])