上一页 1 ··· 36 37 38 39 40 41 42 43 44 ··· 71 下一页
摘要: http://poj.org/problem?id=2411下次还是去学习下dfs的写法吧 自己乱写的好像有点乱 乱七八糟改了一通过了以1 1 表示横着的 1 0 表示竖着的 枚举每一行的状态 再枚举前一行的状态判断是否可以同存注意最后一行要特殊判断一下 0夹着着的1必须为偶数 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 3010 8 #define LL __int64 9 LL dp[15][N],o[2][N],k[15];10 int main()1. 阅读全文
posted @ 2013-08-17 19:42 _雨 阅读(321) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3254第一个状压题 思路挺好想 用二进制表示每行的状态 然后递推用左移 右移来判断是不是01间隔出现 c大神教的 我的代码WA在这个地方了。。改了点 就A了 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define mod 100000000 8 #define LL long long 9 int a[15][15];10 LL dp[15][5050],s[15],num[2][5050],k[15],pp[15];1. 阅读全文
posted @ 2013-08-16 22:45 _雨 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 题目链接推了半个下午。。写的三重超时了 加了点单调队列的思想 优化了下过了dp[i][j] 第二组的最右边的人选第J个人 那最左边肯定选第j-1个人 肯定是选相邻的dp[i][j] = min(o,dp[i-1][j-2]+(h[j]-h[j-1])*(h[j]-h[j-1])) 加个变量o保存 到j为止 最优的一个位置 j-2得满足条件 1 #include 2 #include 3 #include 4 #include 5 #define N 5010 6 #define M 3010 7 #define INF 0xfffffff 8 using namespace std; 9 i. 阅读全文
posted @ 2013-08-16 18:44 _雨 阅读(268) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1191黑书上P116 想了挺久 没想出来 想推出一公式来着 退不出来。。想偏了 正解:递归 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define INF 0xfffffff 9 #define LL long long10 int dp[20][10][10][10][10];11 int aa[10][10],n;12 int divide(int k,int a,int b,int c,int. 阅读全文
posted @ 2013-08-16 18:33 _雨 阅读(228) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1160算水过的吧 四重循环没优化 CZ说爆可过 就爆了dp[i][j] = min(dp[i][j],dp[i-1][g]-s) 第i个点建在第j个村庄上 s 是这个点比上个点少的距离 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 1010 9 #define INF 0xfffffff10 int h[N],dp[40][N];11 int main()12 {13 int ... 阅读全文
posted @ 2013-08-15 22:52 _雨 阅读(185) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4681枚举A串和B串包含C串的区间 枚举区间端点算左右两端最长公共子序 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 1010 8 char s1[N],s2[N],s3[N]; 9 int dp1[N][N],dp2[N][N];10 struct node11 {12 int l,r;13 }p1[N],p2[N];14 int main()15 {16 ... 阅读全文
posted @ 2013-08-15 22:09 _雨 阅读(172) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4678之前写了一并差集找连通块 貌似不对 比赛时写的dfs爆栈了 只好用bfs了单独数字块 为1空白+数字块 数字数%2+1异或 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 1010 9 int dis[8][2] = {1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};10 int n,m,k;11 int vis[N][. 阅读全文
posted @ 2013-08-15 21:01 _雨 阅读(246) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3368追完韩剧 想起这题来了 想用线段树搞定来着 结果没想出来。。然后想RMQ 想出来了算是离散吧 把每个数出现的次数以及开始的位置及结束的位置记录下来 以次数进行RMQ 再特殊处理下区间端点就OK 了WA一次 盯了半小时 原来少了个=号 好吧好吧。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 200005 9 struct node10 {11 int s,e,a;12 ... 阅读全文
posted @ 2013-08-15 00:33 _雨 阅读(208) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3264RMQ讲解http://dongxicheng.org/structure/lca-rmq/j = log2Kdp[i][j] = max(dp[i][j-1]+dp[i+(1 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 50005 9 int minz[N][40],maxz[N][40];10 void init(int n)11 {12 int i,j,o = floor(log10(d... 阅读全文
posted @ 2013-08-14 21:24 _雨 阅读(200) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2852区间K值写错了。。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 100010 8 #define lowbit(x) (x&(-x)) 9 int s[N>1;18 if(p>m)19 add(p,da,m+1,r,w=r)27 return s[w];28 int m = (l+r)>>1,ans=0;29 if(am... 阅读全文
posted @ 2013-08-14 19:42 _雨 阅读(231) 评论(0) 推荐(0) 编辑
上一页 1 ··· 36 37 38 39 40 41 42 43 44 ··· 71 下一页