上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 15 下一页
摘要: 链接:http://poj.org/problem?id=2353题意:给定一矩阵,求从第一层走到最后一层,的最小花费, 每次只能走到相邻的位置,,输出最小花费路径;思路:看完题想到 DP 方程为 dp[i][j] = min( dp[i][j-1], dp[i][j+1], dp[i-1][j] )+cost[i][j];可是 dp[i][j] 与 dp[i][j-1]和dp[i][j+1]有关感觉不靠谱,可是又没想到别的有效的办法;后来又看了下发现到达某一层后每次只会选择一个方向, 要么左要么右, 于是我们就可以做两次比较;dp[i][j] = min( dp[i][j-1], dp[i- 阅读全文
posted @ 2013-01-10 16:30 淡墨æ末央 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2829View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <cmath> 6 #include <vector> 7 #include <alg 阅读全文
posted @ 2013-01-09 22:02 淡墨æ末央 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=2267&mosmsg=Submission+received+with+ID+11118596View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #incl 阅读全文
posted @ 2013-01-09 21:09 淡墨æ末央 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=3612题意:有N根柱子, 高度确定, 现在要使它们连接起来,划分为相邻的柱子的高度差 h *C, 还可以加高度, 花费为所加高度 x 的平方;求最小花费;思路:朴素的想法: 用dp[i][j] 代表第 i 根柱子高度为 j 时的最小花费, 那么 dp[i][j] = dp[i-1][k] + abs( j-k ) * C + (j-a[i])^2;复杂度为 10^5*10^2*10^2 = 10^9 TLE 无压力 ;再来看上面的式子, 去绝对值得到 dp[i][j]=dp[i][k]+(j-k)*C+j-a[i]^2 = dp[i] 阅读全文
posted @ 2013-01-09 15:37 淡墨æ末央 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1395思路: 由题意得N=2^x(x>=1)为偶数, 所以当 n 也为偶数时 N%n必为偶数, 故不存在;当n为奇数时,利用同余定理求;View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <cmath> 6 using namespace std; 7 8 int main( ) 9 阅读全文
posted @ 2013-01-08 22:09 淡墨æ末央 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1262View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 int a[10005]={0}; 5 void fun( ) 6 { 7 a[1]=a[0]=1; 8 for( int i=4; i<10005; i+=2 ) 9 a[i]=1;10 for( int i=3; i <= ( int )sqrt( 10005 ); i+=2 )11 {12 ... 阅读全文
posted @ 2013-01-08 22:02 淡墨æ末央 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576思路:由题意可知,一定有解,而且解空间很小, 故可以枚举;M=9983, n=A%M gcd( b,M )==1, ans=(A?B)%M,则 n == (ans*b)%M;因为: A%M == (A/B*B)%M==(A/B%M * B%M)%M== (ans*B%M)%M;View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string.h> 4 using namespace st 阅读全文
posted @ 2013-01-08 21:58 淡墨æ末央 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4279题意:给定一个数N, 在[1,N)中的数M, gcd( M, N ) != 1, 且N%M != 0; 那么M就为N的一个special number, f( x ) 为统计 x 的special number的个数, 如果f( x )为奇数,那么x就为一个real numbers. 求给定区间的realnumber数.思路:先看f(x),由题意得f(x)=x-phi( x ) - g(x)+1;( phi(x)为欧拉函数, g(x)为因子个数, +1 是因为1在phi(x)和g(x)中都算了 ) 阅读全文
posted @ 2013-01-08 21:21 淡墨æ末央 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=1655题意: 求树的重心;树的重心为去掉该节点使其形成的森林中的树的最大的节点数最小;思路:对于一棵树的任意一个节点做一次DFS就能遍历整棵树, 去掉某节点时, 遍历其子树的节点个数,和为sum那么另一个子树的节点为N-sum-1;View Code 1 #include <cstdio> 2 #include <cstring> 3 const int M=20005; 4 int T, N, t, ans, r, x, y; 5 int h[M*2], sum[M*2];// re[M*2]; 6 stru 阅读全文
posted @ 2013-01-07 20:19 淡墨æ末央 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=1088题意: 中文题;思路:暴力每一个点作为起点DFS; 对于每个点比较其四周的点比较View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <stdlib.h> 6 #include <cmath> 7 using namespace std; 8 int N, M; 9 struct Node 10 {11 i 阅读全文
posted @ 2013-01-07 14:39 淡墨æ末央 阅读(148) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 15 下一页