- 博客(114)
- 资源 (1)
- 收藏
- 关注
原创 51nod1503 猪和回文
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1503思路:因为要求路径回文,所以可以考虑同时从起点和终点出发,中间路径相同最后再某处相遇。第一次多线程dp,两次优化空间,很有趣AC代码:#include<bits/stdc++.h>const int MAXN = 5e2 + 5;const...
2018-03-20 08:45:50
327
原创 51nod1732 51nod婚姻介绍所(DP)
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1732思路:简单的dp,预处理字符串的自匹配的就好,if str[i]==str[j] 有 dp[i][j] = 1+dp[i+1][j+1],用输入输出挂加速读入写出AC代码:#include<stdio.h>#include<math.h...
2018-03-20 08:38:13
262
原创 51nod1086 背包问题 V2
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1086思路:多重背包,二进制分解思路AC代码:#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>const int ...
2018-03-20 08:20:55
201
原创 51nod1051 最大子矩阵和
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1051思路:定义dp[i][j][l]为以第i行第j列为左下角元素的长度为l最大子矩阵和,于是dp[i][j][l] =max(dp[i-1][j][l] + sum(j,j+l-1));然后预处理后缀和,滚动数组优化一下空间即可#include<stdi...
2018-03-19 22:55:16
212
原创 51nod1021 石子归并
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1021思路:简单的区间DP,预处理前缀和就好AC代码:#include<bits/stdc++.h>using namespace std;const int MAXN = 1e2 + 5;const int MOD = 1e9 + 7;l...
2018-03-19 22:33:56
235
原创 51nod1043 幸运号码
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1043思路:数位dp,因为N最多1000,所以可以定义dp[i][j]为长度为i和为j的数的数量,然后dp[i][j] = sum{dp[i][j-k],k∈[0,9]}最后统计的时候就是乘法原理,注意前缀0AC代码:#include<bits/stdc+...
2018-03-19 22:26:40
236
原创 51nod1636 教育改革
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1636思路:先按难度系数排序,然后定义dp[i][j][k]表示,第i天安排第j门课程,作业量为 第j们课程的最小作业量+k的前i天最大作业量之和,之所以这样定义k,是因为课程的最小最大作业量范围太大,但是差值很小,所以可以定义为在区间内的位置来定义,然后转移就...
2018-03-19 22:06:08
246
原创 51nod1101 换零钱
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1101思路:完全背包AC代码:#include<bits/stdc++.h>using namespace std;const int SIZE = 13;const int value[13] = { 1, 2, 5, 10, 20, 50,...
2018-03-19 20:45:30
225
原创 51nod1270 数组的最大代价
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1270思路:可知,要使最大代码取得最大值,那么a[i]的每一位都应是取得上限或者下限,也就是1或者b[i],然后分情况dp就好,O(n)AC代码:#include<bits/stdc++.h>using namespace std;const i...
2018-03-19 20:39:17
194
原创 51nod1049 最大子段和
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1049思路:O(n)边读入边处理,如果前面的子段和大于0,那么就用当前的加上前面的,否则就是当前的,并随时更新最大和就是AC代码:#include<bits/stdc++.h>using namespace std;const int MOD =...
2018-03-19 20:11:20
203
原创 51nod1085 背包问题
原题链接;https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085思路:01背包,不用说了。。AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const int MAXN = 1e4 + 5;const d...
2018-03-19 20:09:04
196
原创 51nod1134 最长递增子序列
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1134思路:经典的LIS问题,nlogn做法:考虑dp[i]为长度为i的最长上升子序列的末尾元素,那么对于长度为i的最长子序列,如果当前元素为j,并且dp[i]>j,那么我们可以考虑用j替换前面的元素,因为末尾元素越低的话,后面的元素就有更多的机会构造出更...
2018-03-19 20:03:56
195
原创 51nod1183 编辑距离
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1183思路:很类似于LCS,不过多一种情况而已,定义DP[i][j]为a以i结尾,b以j结尾的编辑距离,然后如果a[i]==b[j],那么dp[i][j]=dp[i-1][j], 否则的话dp[i][j] = min(dp[i - 1][j], min(dp[i...
2018-03-15 10:42:42
222
原创 51nod1006 最长公共子序列Lcs
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1006思路:定义DP[i][j]为A串以i结尾,B串为j结尾的子序列的最长公共子序列长度,则 if(a[i]==a[j])dp[i][j] = dp[i-1][j-1]+1,else dp[i][j] = max(dp[i-1][j],dp[i][j-1]); ...
2018-03-15 10:33:52
146
原创 51nod1010 只包含因子2 3 5的数
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010思路:预处理+二分AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const long long MAXN = 1e18 + 5555;i...
2018-03-15 09:48:50
249
原创 51nod1014 X^2 Mod P
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1014思路:暴力枚举即可,注意溢出AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const int MAXN = 1e4 + 5;int ma...
2018-03-15 09:36:24
200
原创 51nod1024 矩阵中不重复的元素
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1024思路:技巧题,取对数存set就行AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const int MAXN = 1e5 + 5;const...
2018-03-15 09:33:12
222
原创 51nod1007 正整数分组
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1007思路:01背包,设背包最大重量为总和的一半,然后dpAC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const int MAXN = 1e4 ...
2018-03-15 09:17:11
180
原创 51nod1031 骨牌覆盖
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1031思路:随便写写画画就知道,这就是个菲波拉契数列,因为对于2*N的方格,当前位置(也就是最右边),要么横着放两个,方案数就是2*(N-2)的方案数,或者竖着放一个,方案数就是2*(N-1)的方案数,数据又小,递推求解即可。AC代码:#include<b...
2018-03-15 08:21:23
211
原创 51nod1042 数字0-9的数量(数位DP)
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1042思路:就是统计啦,有点麻烦,注意细节,看代码AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const int MAXN = 1e5 + 5;...
2018-03-15 08:16:48
202
原创 51nod1050 循环数组最大子段和
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050思路:这里有两种情况,一种是数组最大字段和是循环的,一种是不循环的,不循环的可以直接dp求解,可循环的数组最大字段和不好找,但是最小字段和好找,dp出最小字段和,然后用总和减去就是所求值AC代码:#include<bits/stdc++.h>...
2018-03-15 08:07:39
206
原创 51nod1067 Bash游戏 V2
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1067思路:dp打表找下规律即可,如果A有一种选择之后B为输,那么A赢,如果B全部为赢,A输AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;cons...
2018-03-15 08:05:05
218
原创 51nod1092 回文字符串(区间DP)
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1092思路:区间DP,如果str[i]==str[j],dp[i][j] = dp[i+1][j-1],否则 dp[i][j] = min(dp[i+1][j],dp[i][j+1])+1, O(n^2)状态,O(1)转移AC代码:#include<bi...
2018-03-14 14:01:53
211
原创 51nod1094 和为k的连续区间(前缀和)
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1094思路:维护前缀和sum的最小下标,然后枚举i看是否有对应的sumAC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const int MAXN ...
2018-03-14 13:54:33
177
原创 51nod1095 Anigram单词
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1095思路:排序存储到map里面,另外主要判断当前要查询的单词是否有一个原单词与它相同,如果有就减去AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;...
2018-03-14 13:46:42
152
原创 51nod1119 机器人走方格 V2(组合数学)
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119思路:组合数学最基本的各路模型,从(0,0)点走到(n,m)点,只能想右或者下的方案数,等于C(N+M,N) 也就是从一共N+M步中选择N步向下AC代码:#include<bits/stdc++.h>using namespace std;...
2018-03-14 13:44:58
297
原创 51nod1126 求递推序列的第N项
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126思路:矩阵快速幂 或者找循环节AC代码:#include <iostream>using namespace std;int f[300] = { 1, 1, 1 }; // 根据规律可知,一定存在循环节int main()...
2018-03-14 13:41:53
153
原创 51nod1133 不重叠的线段
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1133思路:线扫,加贪心,将线段按终点升序排序AC代码;#include<bits/stdc++.h>using namespace std;const int MAXN = 50005;struct line { int start, e...
2018-03-14 11:32:46
201
原创 51nod1138 连续整数的和
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1138思路:设数列首项为a,长度为n,那么a,n要满足方程,n*(2*i+n-1) = 2*N,然后i不好枚举,我们可以从大到小枚举n,根据方程可知,n是sqrt(2*N)级别AC代码:#include<bits/stdc++.h>using na...
2018-03-14 11:17:29
158
原创 51nod1266 蚂蚁
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1266思路:我们可以知道,假设一只向右一只向左,相遇后,向右的向左,向左的向右,也就是说,其实可以等同看待,所以当求最短时间时,每只蚂蚁向离端点近的地方走,求最长时间时,每只蚂蚁向离端点远的地方走就是AC代码:#include<bits/stdc++.h&...
2018-03-14 10:56:23
165
原创 51nod1278 相离的圆
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278思路:贪心+线扫,先将圆预处理成点,分为起点与终点,我们对每一个终点计算他后面的与他相离的圆的数目,每遇到一个起点,就那么可能的相离的圆的数目就要减1AC代码:#include<bits/stdc++.h>using namespace st...
2018-03-14 10:36:50
201
原创 51nod1279 扔盘子
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1279思路:贪心, 可以知道 如果上面的宽度比下面还低的话, 是不可能到达下面的,于是可以预处理井的宽度,并从下到上贪心放置盘子即可AC代码: #include<bits/stdc++.h>using namespace std;const i...
2018-03-14 10:25:17
171
原创 51nod1315 合法整数集
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1315思路:分解二进制位,详情看代码AC代码:#include<bits/stdc++.h>using namespace std;int cnt[34];int main() { int n, t, x; scanf("%d %d", ...
2018-03-13 22:15:57
214
原创 51nod1417 天堂里的游戏
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1417思路:根据样例,就是求一个p关于AB的公式即可,PA-(A+B)/2(1-P)=(1-P)B-(A+B)P/2 ; 所以 P=a+3b/(4a+4b)AC代码:#include<bits/stdc++.h>using namespace s...
2018-03-13 22:06:04
469
原创 51nod1428 活动安排问题
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428思路:贪心,按开始时间排序,并用数组保存每个教室当前活动的结束时间AC代码:#include<bits/stdc++.h>using namespace std;struct node { int start, end; bool op...
2018-03-13 21:49:51
106
原创 51nod1432 独木舟
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432思路:贪心,一个船最做坐两个人,我们考虑最重的一个人,那么如果最轻的人都不能与他同乘一艘船,那么其他人更不能,所以从两边开始遍历即可AC代码:#include<bits/stdc++.h>using namespace std;int a[10...
2018-03-13 21:42:36
170
原创 51nod1413 权势二进制
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1413思路:因为权势二进制,只能由01构成,所以只要枚举记录各位上的最大数,就是所需要的数的个数AC代码:#include<bits/stdc++.h>using namespace std;int main() { int n; scan...
2018-03-13 21:34:49
154
原创 51nod1433 0和5
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1433思路:九余定理,https://www.cnblogs.com/zzqc/p/6684794.html,然后只要各位上的数加起来是9的倍数,并且有一个0及以上的0即可,然后5放前面,0放后面,满足最大。AC代码:#include<bits/stdc+...
2018-03-13 21:31:48
183
原创 51nod1629 B君的圆锥
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1629思路:推导公式,大佬博客AC代码:#include<bits/stdc++.h>using namespace std;const int MOD = 1e9 + 7;const double PI = acos(-1.0);int ...
2018-03-13 20:44:53
171
原创 51nod1489 蜥蜴和地下室
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1489思路:看数据,标准的dfs,先打掉最左边和最右边的怪,然后对中间的深搜,细节看代码AC代码:#include<bits/stdc++.h>using namespace std;const int MAXN = 10 + 5;int n...
2018-03-12 21:30:56
205
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人