- 博客(22)
- 资源 (4)
- 收藏
- 关注
原创 poj 1088 DFS+记忆化搜索
开始用的BFS。。。超时。。。。AC代码如下:#include #include #include #include #include using namespace std;struct Node{ int x, y; int h; bool operator<( const Node &b )const{ return h < b.h; }};int M
2014-01-18 09:17:08 678
原创 poj 1083 DP
AC代码如下:#include #include #include #include #include using namespace std;int main(){ int dp[210]; int N, T, ans; cin >> T; while( T-- ){ cin >> N; memset( dp, 0, sizeof( dp ) ); for
2014-01-17 19:47:58 720
原创 poj 1050 DP
开始就想到分成多组最大连续子序列来求,但是这样就是10^6,以为会超时,所以一直想优化,但苦苦却不可得,最后看了别人的报告发现都是这么求得。。。。T_TAC代码如下:#include #include #include #include using namespace std;int calc_max( int a[], int N ){ int lis, pre; lis
2014-01-17 16:19:46 743
原创 Lightoj 1157 数位DP
A掉了poj1934 之后得到的思路。。。。可以点进去看一下那一题的思路:点击打开链接AC代码如下:#include #include #include #include #include #include using namespace std;char a[1100], b[1100];int lcm;int dp[1100][1100];int dps[1100
2014-01-17 11:28:04 801
原创 poj 1934 DP
参照别人的思路:点击打开链接它的思路是:1)首先按照常规的方法求出最长公共子序列的长度也就是用O(MN)的那个动态规划,结果放在二维数组dp里dp[i][j] = { 字串a的1~i部分与字串b的1~j部分的最长公共子序列的长度 }2)求辅助数组last1[i][j] = { 到下标i为止,字符j在字串a中最后一次出现的下标 }last2[i][j] = { 到
2014-01-17 11:03:48 904
原创 poj 2411 状态压缩DP
解题报告:http://www.cppblog.com/sdfond/archive/2009/07/31/91761.htmlAC代码如下:#include #include #include #include #include using namespace std;vector hashs[1<<13];int M, N;long long dp[13][1<<13
2014-01-17 09:48:54 820
原创 Lightoj 1421 DP
先求出从左边开始的最长递增子序列,然后求出从右边开始的最长递增子序列。然后遍历一遍,在i位置的满足要求的最大长度就是 min(L_LIS, R_LIS );AC代码如下:#include #include #include #include using namespace std;int N;int num[110000];int L[110000], R[11000
2014-01-15 20:33:44 661
原创 Lightoj 1032 数位DP
AC代码如下:#include #include #include #include using namespace std;int digit[33];long long dp[33][33][2];long long DFS( int pos, int count, int pre, bool limit ){ if( pos <= 0 ){ return coun
2014-01-14 20:34:05 684
原创 Uva 10382 贪心
应该在整个n里贪心AC代码如下:#include #include #include #include #include #include using namespace std;struct Node{ double O, R; double f, l; int flag; bool operator<( const Node &b )const{ if( f
2014-01-14 16:46:24 628
原创 Lightoj 1106 贪心
首先我们可以枚举要走过湖泊数X,然后算出从1到X的时间。那么在这个前提下,我们可以认为fisher可以从一个湖泊“瞬间转移”到另一个湖泊,即在任意一个时刻可以从1到X中任选一个钓鱼。 此时,走路的时间确定了,钓鱼的次数就确定了(每次5分钟),然后每次都选取f[i]最大的钓,这种贪心的思想最终能够得到一个钓鱼序列。 你可能会跟我一样有一个疑问:因为就算是在这种情况
2014-01-13 15:48:15 855
原创 Timus 1012 DP
AC代码如下:#include #include #include #include using namespace std; #define MAXN 9999#define MAXSIZE 10#define DLEN 4class BigNum{ private: int a[50]; //鍙互鎺у埗澶ф暟鐨勪綅鏁� int len;
2014-01-13 11:08:22 1227
原创 Timus 1013 DP
滚动数组!AC代码如下:#include #include #include #include using namespace std; #define MAXN 9999#define MAXSIZE 10#define DLEN 4class BigNum{ private: int a[500]; //可以控制大数的位数 int len;
2014-01-13 11:05:11 671
原创 Timus 1010 DP
AC代码如下:#include #include #include #include using namespace std;long long h[100010];int main(){ int N; int ans; while( scanf( "%d", &N ) != EOF ){ for( int i = 1; i <= N; i++ ){ scanf
2014-01-13 11:04:29 611
原创 Timus 1009 DP
AC代码如下:#include #include #include #include using namespace std;long long dp[2][20];int N, K;long long DFS( int statu, int pos ){ if( pos > N ){ return 1; } if( dp[statu][pos] != -1 ){
2014-01-13 11:03:48 640
原创 poj 2044 DFS
AC代码如下:#include #include #include #include #include using namespace std;struct Node{ int a, b, c, d;};int statu[366];int N;int moves[][2] = { { 0, 0 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, {
2014-01-11 15:17:33 873
原创 poj 3635 搜索+优先队列
一定要用优先队列。。。。。TLE了一上午了。。。。。。AC代码如下:#include #include #include #include #include #include using namespace std;#define MAX 0x3f3f3f3fstruct Node{ int sum_cost; int pos; int v; bool oper
2014-01-11 10:56:18 738
原创 hdu 3681 二分枚举答案+dp判断答案
一开始以为是搜索,然后不知道怎么办了。。。那么多状态。。。因为那个夏天的风的分类是在搜索里面,最后看了解题报说是dp。。。。。思路:先用BFS搜出Y与G,G与F,F与Y的距离,然后就用二分枚举答案,用dp来判断答案是否能行。dp就是一个TSP问题。。。。我写的时候有一个地方要注意,就是dp判断里面结束的判断。。。一开始用的是〉~~的。。最后发现这样不行。。。。因为如果一个power
2014-01-10 21:26:23 770
原创 poj 1001 大数
坑 不读说。。。上代码。。。。poj的discus上有测试。。。。慢慢测就是了。。。AC代码如下:#include #include #include #include using namespace std;int num[10000];char R[20];int N, point, A;void init(){ int last = strlen( R );
2014-01-08 11:05:16 568
原创 lightoj 1173 记忆化搜索
题目的意思是有N个升高不同的人,求高矮间隔排列的数目,并且依据题目的意思,队长肯定在第一个。然后这一题可以这样想a1 a2 a3 a4 a5.....ak 表示已经排列好了的人,然后还有n个人那么用 dp[n][m][1]来表示 排剩下的n个人,并且这n个人中有m个人比ak高,且接下来排的第一个人要比ak高的 排列数 用 dp[n][m][0]来表示
2014-01-07 21:44:30 902
原创 hdu 1142 记忆化搜索
首先用迪杰斯特拉算法求出各点到2的最短距离,然后用记忆化搜索算出 各点到2的可能路径数dp[i]AC代码如下:#include #include #include #include using namespace std;#define MAX 0x3f3f3f3ftypedef struct{ int to, next, weight;}Edge;Edge edg
2014-01-02 19:38:44 659
原创 扩展欧几里得算法
当在求 ( a / b ) % MOD 时由于有分数不能直接求要转化成 a % MOD * ( x % MOD + MOD ) % MODx的求法如下:void EGCD( LL a, LL b, LL &x, LL &y ){ if( b == 0 ){ x = 1; y = 0; return; } EGCD( b, a % b, x, y ); LL t
2014-01-01 19:44:48 899 2
原创 Lightoj 1170 卡特兰数+扩展欧几里得算法
1.预处理先求出1e10范围内的所有完美的数2.一个有n个值的二叉排序树的个数: 先将这n个数排序,然后 可以选第1个数为根,那么就变成了 构造 0个节点的左子树 与 n-1个节点的右子树 选第2个数为根,那么就变成了 构造1个节点的左子树 与 n-2个节点的右子树
2014-01-01 19:41:56 1079
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人