随笔分类 -  spoj

spoj 66. Cross-country
摘要:水题 最长公共子序列#include #include #include #include using namespace std;int dp[1010][1010],a[1010],b[1010];int n,m;int LCS(int x, int y){ if(x==-1 || y==-1) return 0; if(dp[x][y]!=-1) return dp[x][y]; if(a[x]==b[y]) return dp[x][y]=LCS(x-1, y-1)+1; else return dp[x][y]=max(LCS(x-... 阅读全文
posted @ 2013-08-16 11:09 风流monkey 阅读(154) 评论(0) 推荐(0)
spoj 364. Pocket Money
摘要:dp 状态转移方程 dp[i][j]=max(dp[i][j],dp[i][k](*/+)dp[k+1][j]) , dp[i][j]=min(dp[i][j],dp[i][k](*/+)dp[k+1][j]) 和uva 上的10700非常相似 但是 spoj上有数字0所以就不能用简单的栈的思想来做了 选择用dp来做#include #include #include #include using namespace std;long long a[110];long long b[110];long long dp[110][110];bool vis[110][110];char s[11 阅读全文
posted @ 2013-08-09 21:06 风流monkey 阅读(173) 评论(0) 推荐(0)
spoj 394. Alphacode
摘要:需要注意的是0这个问题 0是不可能单独代表一个字母的 只能与前面的数组组成字母 a[i]是1-9时 dp[i]=dp[i-1],当a[i]与a[i-1]能组成10-26时 dp[i]=dp[i-1]+dp[i-2]。#include #include #include #include long long dp[5010];char s[5010];int a[5015];int is_ok(int x){ if(x>=10 && x<27) return 1; return 0;}int main(){ while(scanf("%s",s)! 阅读全文
posted @ 2013-08-09 18:36 风流monkey 阅读(166) 评论(0) 推荐(0)
spoj 297. Aggressive cows
摘要:二分查找最小值#include #include #include #define N 100010using std:: sort;int a[N];int n,m;int solve(int x){ int cas=0; int nx=1; for(int i=2; i=x) { cas++; nx=i; } } return cas+1;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d ... 阅读全文
posted @ 2013-08-03 20:10 风流monkey 阅读(218) 评论(0) 推荐(0)
spoj 147. Tautology
摘要:借鉴别人的思路,dfs+栈 枚举每一个元素的真假值 然后利用栈,从后往前读入,,, 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 bool num[30]; 9 char s[120];10 int ans[26];11 bool b[26];12 int k;13 bool dfs(int cur)14 {15 if(cur==k)16 {17 stackq;18 for(int i=strlen(s)-1; i>=... 阅读全文
posted @ 2013-08-02 16:10 风流monkey 阅读(107) 评论(0) 推荐(0)