上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 18 下一页
摘要: 问题描述:给出两个字符串X, Y,求一个串同时是X, Y的子串并且是所有满足条件里的最长的串。分析:题目是一个动态规划问题。设c[i][j]表示 x = {x0, x1, x2, .. xi-1}和 y = {y0, y1, y2, .... yj-1},的最长子序列长度, x, y的字串为 z= {z0, z1, z2, ... zk}。所以有一下规律:当x[i-1] = y[j-1]时,z[k] = x[i-1] = y[j - 1], c[i][j] = c[i-1][j-1] + 1;当x[i-1] != y[j-1] 且 z[k] != x[i-1], c[i][j] = c[i.. 阅读全文
posted @ 2011-11-29 19:30 AC_Von 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 证明:从题目可以知道 A: (1 + x2/1! + x4/2! + ....); B: (1 + x/1! + x2/2! + x3/3! + ...); C:(1 + x2/1! + x4/2! + ....); D: (1 + x/1! + x2/2! + x3/3! + ...);所以有: G(x) = (1 + x2/1! + x4/2! + ....)2 * (1 + x/1! + x2/2! + x3/3! + ...)2;由于泰勒展开式:ex = 1 + x/1! + x2/2! + x3/3! + ...e-x = 1 - x/1! + x2/2! - x3/3! + ... 阅读全文
posted @ 2011-11-27 13:13 AC_Von 阅读(516) 评论(0) 推荐(0) 编辑
摘要: 指数型生成函数公式(其中一个):指数阶一般求解的问题:已知有n种颜色的求,第1种X1个,第2种X2个,第3种X3个。。。求从中取m个的方案数(组合数)。公式中的ak/k!就是所求的组合数,ak为排列数。代码中:for(i = 1; i < n; i++) { for(j = 0; j <= m; ++j) { for(k = 0; k + j <= m && k <= val[i]; ++k) { c2[j + k] += c1[j]/Factorial(k); } ... 阅读全文
posted @ 2011-11-26 21:27 AC_Von 阅读(1265) 评论(0) 推荐(0) 编辑
摘要: 很裸的生成函数:My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 100;int c1[N], c2[N];int val[N];int main() { //freopen("data.in", "r", stdin); int i, j, k, t, ans; while(~scanf("%d", &t)) { while(t--) { for(i 阅读全文
posted @ 2011-11-26 20:04 AC_Von 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 先打表,否则TLEMy Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 32767;int c1[N+1], c2[N+1];int main() { //freopen("data.in", "r", stdin); int n, i, j, k; for(i = 0; i <= N; i++) { c1[i] = 1; c2[i] = 0; } for(i = 2; i & 阅读全文
posted @ 2011-11-26 18:55 AC_Von 阅读(233) 评论(0) 推荐(0) 编辑
摘要: /*用并查集做可以,不过总觉得别扭。明明是图论的题嘛。今天在师兄博客里看到这个 解法,用二分限定所取的边的权值。设最大与最小差为lim,最小为low。所以low <= weight <= low + lim;所以,用二分取到lim最小的一个。ps:限定low时需与熬用到hash,否则直接存m个weight会TLE。不能抵达终点输出-1,我晕,因为这个错了好几次。。。T_T*///My Code: 234+MS#include <iostream>#include <cstdio>#include <cstring>#include <set 阅读全文
posted @ 2011-11-26 17:53 AC_Von 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 从组合数的定义可以知道。C(n, m) = C(n-1, m) + C(n-1, m-1);所以,根据这个公式可以递归的求得组合数,代码如下:long long C(int n, int m) { if(m == 0 || n == 0 || n == 1 || m == n) return 1; if(aug[n][m] != 0) return aug[n][m]; aug[n-1][m] = C(n-1, m); aug[n-1][m-1] = C(n-1, m-1); return aug[n-1][m] + aug[n-1][... 阅读全文
posted @ 2011-11-26 11:33 AC_Von 阅读(905) 评论(0) 推荐(0) 编辑
摘要: A题:看错题意了,WA了好几好几次。。。B题:闲的蛋疼多加了一个变量,nnd,我吃饱撑的!!C题:for循环的结束条件写错了,我靠!!!ps:各种错误,各种马虎,rating暴跌,T_T,悲摧啊。看来以后的适应一下晚上做题。。。 阅读全文
posted @ 2011-11-26 10:42 AC_Von 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 这里可以看成给一个面值为m的钱币,要求将它换成n种不同的面值都为1的钱币,同时要求每种钱币供应的上下限。然后就是生成函数模板了。。。My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 110;int c1[N], c2[N];int MIN[N], MAX[N];int main() { //freopen("data.in", "r", stdin); int n, m, i, 阅读全文
posted @ 2011-11-25 21:59 AC_Von 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 没有看到Your program should be able to handle up to 100 coins. WA了n次。。。处理起来有点麻烦,看到大牛的思路是开一个二维数组c[i][j],表示用j个硬币组成大小为i的数。把j限定在100以下(有点dp的感觉,呵呵)。就可以了。详见代码:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 250;int c1[N+1][N+1], c2[N+1][N+1];int val[5] 阅读全文
posted @ 2011-11-25 21:28 AC_Von 阅读(276) 评论(0) 推荐(0) 编辑
摘要: /*用砝码秤重量,按照左物右码的话,砝码的值可以取负。因为砝码最多就一个,所以不许要一般模板里的k 那一重循环,直接去砝码个数为0, 1的两种情况就行。开始把重量取负时那种情况想错了,WA了好几次。。。T_T*///My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 10007;int c1[N], c2[N];int val[107];int main() { //freopen("data.in" 阅读全文
posted @ 2011-11-25 20:13 AC_Von 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 貌似跟1171一样的,呃。。。My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 100;struct node { int val; int num;} a[55];int c1[N], c2[N];int main() { //freopen("data.in", "r", stdin); int t, n, i, j, sum, k, m; while(cin >> 阅读全文
posted @ 2011-11-24 17:07 AC_Von 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 比1085多了一些变化,见代码。My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 250007;struct node { int val; int num;} a[55];int c1[N], c2[N];int main() { //freopen("data.in", "r", stdin); int n, i, j, sum, k; while(cin >> 阅读全文
posted @ 2011-11-24 16:43 AC_Von 阅读(209) 评论(0) 推荐(0) 编辑
摘要: /*按照母函数的思路,然后模拟三个括号相乘的过程。因为题目已经限定好了硬币只能是1、2、5。所以可以写成:(1 + X + X^2 + ...)(1 + X^2 + X^4 + X^6 + ...)(1 + X^5 + X^10 + X^15 + ...)其中三个括号元素的个数分别是输入的num_1, num_2, num_3。然后就是模拟多项式相乘了。*///ps:代码有点水,一步一步乘的,反正就三个括号,费不了多大劲,^_^//My Code:#include <iostream>#include <cstring>#include <cstdio>us 阅读全文
posted @ 2011-11-24 15:34 AC_Von 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 母函数模板题,就是稍微改了一下。My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 307;int c1[N], c2[N];int main() { //freopen("data.in", "r", stdin); int n, i, j, k; while(cin >> n, n) { for(i = 0; i <= n; i++) { c1[i] = 1; 阅读全文
posted @ 2011-11-24 14:26 AC_Von 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 去你妹的并查集,没纠结死我!按速度排序,然后枚举所有的路,知道find(start) == find(end)结束。然后用最大值减去最小值,求其差,取差最小。Code:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int N = 1024;const int inf = 0x6fffffff;class node {public: int x, y, 阅读全文
posted @ 2011-11-23 21:49 AC_Von 阅读(388) 评论(0) 推荐(0) 编辑
摘要: 一牛人说:母函数就是把费脑筋的事转换成多项式计算。好吧,我承认母函数用好的话确实很神奇,比如说这个题。可以把n看成无限个可取用的1,2,3,4,5,,,m这些数组成的。然后就是可以写成母函数的形式G(X) = (1 + X^1 + X^2 + X^3 + ...)(1 + X^2 + X^4 + X^6 + ...)(1 + X^3 + X^6 + ...)...然后就是模拟多项式的计算过程。输入的n是多少就计算到几阶,得到的X^n项的系数就是可能的情况数。My Code:#include <iostream>#include <cstdio>#include < 阅读全文
posted @ 2011-11-23 19:40 AC_Von 阅读(108) 评论(0) 推荐(0) 编辑
摘要: problem 1:贪心,我二了。。。problem 2:对这题表示无语,我担心快速幂函数会超,所以10^6一次分开幂的,WA了,直接用快速幂函数算就对了,我无语了。。。快速幂函数:int exp_mod(int a,int n,int b){ int t; if(n==0) return 1%b; if(n==1) return a%b; t=exp_mod(a,n/2,b); t=t*t%b; if((n&1)==1) t=t*a%b; return t;}problem 3:母函数模板题。problem 4:按速度排序,然后枚举所有的路,... 阅读全文
posted @ 2011-11-22 21:22 AC_Von 阅读(252) 评论(0) 推荐(0) 编辑
摘要: /*发现并查集的应用太巧妙了。。。大体思路:从题中可以看出来如果(i, j)是even的话,sum(i-1) 和 sum(j)的奇偶性相同。(i, j)如果是odd的话则其奇偶行不同。定义奇偶性为朋友,不同则为敌人。这样按照奇偶性分成连个集合。same[i] = {x|sum[x]与sum[i]同奇偶}(即i的朋友集)diff[i] = {x|sum[x]与sum[i]不同奇偶}(即i的敌人集)如果(i, j)是even,则分别合并(same(i-1), same(j))和(dirr[i-1] , diff(j))。如果是odd,则因为不是奇就是偶,所以,一个的朋友和另一个的敌人合并(敌人.. 阅读全文
posted @ 2011-11-22 20:42 AC_Von 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 描述在一个星期三的早上,某同学想用扔硬币的方式来决定是否要去上算法课。他扔n次硬币,如果当中有连续m次以上(含m次)的结果都是正面,那么他就去上课,否则就接着睡觉。(假设每次扔硬币扔出的正反两面的概率都是 0.5。)输入输入的每行有一组数据,分别为n和m(0 <n<= 2000, 0 <m<= 10)。输入以 0 0 结尾。输出对于每组数据,输出他去上课的概率,四舍五入保留小数点后 2 位。 今天队友问我这个题,说是dp的问题。悲摧的开始看错题意了,题目让找连续m次以上的概率。开始思路是建立一个2维dp[i][j],表示仍i次硬币出现j次连续正面朝上的概率。但后来发现实 阅读全文
posted @ 2011-11-22 18:23 AC_Von 阅读(196) 评论(1) 推荐(0) 编辑
摘要: /*思路参考大牛,我脑袋被lv踢了,居然想到用数状数组写。。。思路:并查集,先把不许要删的边用并查集合并,然后把需要删的边逆序加入到并查集中。。。。My Code:*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 100005;struct node { int s; int e;}g[N];int parent[N];int c[N];int ans[N];int Rank[N];bool vis[N];void init(in 阅读全文
posted @ 2011-11-21 20:56 AC_Von 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 很裸的单调队列问题,不过O(n)的算法写出来5188+ms,超5s了。。。谁能告诉我500+ms的神级代码是什么。。.T_TMy Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1000005;struct node { int i; int num;}q[N];int ans[N];int b[N];int main() { //freopen("data.in", "r", st 阅读全文
posted @ 2011-11-20 20:39 AC_Von 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 话说单调队列!= 优先队列。可怜我捧着算导看了半天优先队列。题意读的很费劲,最后问得师兄。就是给定一个M,然后再给一个序列,求给出的序列里连续M个数中的最大值。最后把这些最大值输出,其实就是很裸的单调队列。然后开始在网上搜有关单调队列的资料,从这里http://www.felix021.com/blog/read.php?1965学会的。其实就是维持队列的单调性,别管是单调增还是单调减。队头元素永远是最列的最小值(或最大值)。 #include <iostream>#include <cstdio>#include <cstring>using namesp 阅读全文
posted @ 2011-11-20 17:34 AC_Von 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 开始直接暴力,然后果断挂掉。T_T...后来看到DIcuss里有人说用Binary heap。然后就在想怎么用堆优化,想了半天没想到。然后看大牛的思路。鹈鹄灌顶啊!!!思路:先存数列长度的一半+1,然后建立小顶堆。然后输入剩下的元素,如果输入的元素大于堆顶元素,则把堆顶替换掉。再调整一次堆。My Code:#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int N = 125005;int heap[N];void heap_adjust(in 阅读全文
posted @ 2011-11-19 22:01 AC_Von 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 思路就是快排+二分查找。有重复的数字,多加了一点小处理。My Code:#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 70005;class node {public: int num; int ord;} a[N];bool cmp(node a, node b){ if(a.num == b.num) return a.ord < b.ord; return a.num 阅读全文
posted @ 2011-11-19 19:50 AC_Von 阅读(240) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 18 下一页