算法竞赛入门经典(第二版)----动态规划初步
文章平均质量分 62
wang2147483647
这个作者很懒,什么都没留下…
展开
-
UVA 437(p269)----The Tower of Babylon
#include #include #include #include using namespace std; struct point { int x,y,z; point(int a=0,int b=0,int c=0):x(a),y(b),z(c) {} }; vector g; int n,f[1000]; int cmp(point a,point b) { i原创 2016-02-25 22:54:25 · 204 阅读 · 0 评论 -
UVA 116(p270)----Unidirectional TSP
#include #include #include using namespace std; const int maxn=110; const int INF=1e7; int d[maxn][maxn]; int next[maxn][maxn]; int a[maxn][maxn]; int n,m,first,ans; void solve() { int i,j,k;原创 2016-02-25 22:25:17 · 288 阅读 · 0 评论 -
UVA 12563(p274)----Jin Ge Jin Qu [h]ao
#include #include #include #include using namespace std; const int maxn=10000; struct point { int num,time; bool operator <(const point &rhs) const { return num<rhs.num||(num==rhs.原创 2016-02-27 14:09:00 · 341 阅读 · 0 评论 -
UVA 12186(p282)----Another Crisis
#include #include #include #include #include using namespace std; const int maxn=1e5+50; int n,t; vector son[maxn]; int solve(int u) { if(son[u].empty()) return 1; int num=son[u].size(); i原创 2016-02-27 14:01:42 · 275 阅读 · 0 评论 -
UVA 11584(p275)----Partitioning by Palindromes
#include #include #include #include #include #define hell using namespace std; const int maxn=1000+50; int n,t; string st; int d[maxn]; int s[maxn][maxn]; int check(int l,int r) { while(l<r) {原创 2016-02-27 13:48:53 · 212 阅读 · 0 评论 -
UVA 11584(p275)----Partitioning by Palindromes
#include #include #include #include using namespace std; const int maxn=1000; struct point { int v,k,c,l; }; int d[maxn+50]; int n,cnt[maxn+50]; point g[maxn+50]; int cmp(point a,point b) { re原创 2016-02-27 13:36:33 · 186 阅读 · 0 评论 -
UVA 10285(p304)----Longest Run on a Snowboard
#include #include #include #include const int dx[4]={1,-1,0,0}; const int dy[4]={0,0,1,-1}; using namespace std; int t,r,c,temp,a[105][105],f[110][110]; string st; int dfs(int x,int y) { if(f[x][y原创 2016-02-26 14:17:00 · 226 阅读 · 0 评论 -
UVA 10003(p278)----CUtting Sticks
#include #include using namespace std; const int maxn=100; const int INF=1e7; int d[maxn][maxn]; int l,n,a[maxn]; int solve(int l,int r) { if(d[l][r]<INF) return d[l][r]; for(int k=l+1; k<=r-1原创 2016-02-26 14:09:20 · 187 阅读 · 0 评论 -
UVA 1632(p306)----Alibaba
#include #include #include #include using namespace std; const int INF=0x7f7f7f7f; const int maxn=10000+10; int d[maxn][maxn][2],n; int a[maxn],dl[maxn]; int solve() { for(int i=n-1;i>=0;i--)原创 2016-02-26 13:48:18 · 283 阅读 · 0 评论 -
UVA 1626(p278)----Brackets Sequence
#include #include #include #include #define debu using namespace std; const int INF=1e7; const int maxn=200; char st[maxn]; int d[maxn][maxn]; int check(char a,char b) { if(a=='('&&b==')') return原创 2016-02-26 13:47:04 · 235 阅读 · 0 评论 -
UVA 1220(p282)----Party at Hali-Bula
#include #include #include #include using namespace std; const int maxn=250; int n; char st1[110],st2[110]; vector name; vector son[maxn]; int d[maxn][3],f[maxn][3]; int ID(const string& st) { for原创 2016-02-25 23:54:17 · 287 阅读 · 0 评论 -
UVA 1252(p287)----Twenty Questions
#include #define debu using namespace std; const int maxn=150; const int maxm=(1<<11)+50; int n,m; char item[maxn][15]; int d[maxm][maxm]; int cnt[maxm][maxm]; int solve(int s,int a) { if(d[s][a]!原创 2016-03-26 20:03:38 · 516 阅读 · 0 评论