上一页 1 2 3 4 5 6 ··· 9 下一页
摘要: 题意:给定一个整数矩阵,找到一条严格递减的最长路。 简单的动规题目,dp[i][j]表示走到(i, j)所走过的最长步数,向四个方向转移状态即可。 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 105; 阅读全文
posted @ 2015-04-16 16:25 Popco 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个树形的机器结构,安装服务器,每台服务器恰好跟一台服务器相邻,问最少装几台服务器。 首先DFS把树建立起来,然后动规求解,注意设置无穷大inf后累加要防止超int范围。 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <iostream> 3 # 阅读全文
posted @ 2015-04-14 11:11 Popco 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 超大背包问题,刚开始想复杂了。分段填充背包,前面一大部分用性价比最高的填充,最后一部分动规就可以了。 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2408 Pick apples Time L 阅读全文
posted @ 2015-04-12 21:42 Popco 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个日期范围,判断月和日均为素数的天数。 比较水的题目,for循环中的?:判断语句、日期的打表,可以大幅精简代码。 #include <iostream> #include <cstdio> using namespace std; int day1[15] = {0, 31, 29, 3 阅读全文
posted @ 2015-04-10 16:56 Popco 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 题意:给定N个数,选出其中数量大于(N+1)/2的数 两种方法实现,第一种方法排序,选择中间的那个数。第二种方法搜一遍。 #include <iostream> #include <algorithm> #include <cstring> #include <cstdlib> #include < 阅读全文
posted @ 2015-04-10 15:10 Popco 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 题意:给定n个泥坑路面的初末位置,判断最少需要几个桥才能覆盖这些路面。 贪心法,从每个泥坑的开始位置建桥,然后判断是否覆盖后面的路面,就是分类讨论了。 #include #include #include #include #include #include using namespace st... 阅读全文
posted @ 2015-04-08 23:11 Popco 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个字符串,判断能划分成尽量少的回文串的数量。 dp[i]代表的状态为字符串前i个字符所能划分成的最少回文串的数量。判断回文串可以用递归来判断。 #include #include #include #include using namespace std;char str[1024]... 阅读全文
posted @ 2015-04-07 22:17 Popco 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 比赛时不会动规,现在拿出来再做一遍。 dp[i][j]表示在i时刻使用j次转移得到的最多苹果数 #include #include #include using namespace std;int a[1024], dp[1024][35];int main(){ int n, w; ... 阅读全文
posted @ 2015-04-06 21:02 Popco 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 动规简单题,dp[i][j]表示的状态为字符串a.substr(0, i)和b.substr(0, j)的最长公共子序列。 #include #include #include #include using namespace std;int dp[1024][1024];int main() ... 阅读全文
posted @ 2015-04-06 19:05 Popco 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 题意:给定几首歌的长度,在规定时间内,选择尽量多的曲目,在此前提下选择时间尽量长的歌。 动态规划基础题,刚开始把条件看反了。dp[j]代表在j时间能够唱的最多曲目。 #include using namespace std;int dp[10240], ti[10240];int main(){... 阅读全文
posted @ 2015-04-06 18:55 Popco 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 动态规划基础例题,要理解状态和状态转移方程。。。 #include using namespace std;int kase = 0;int n, T, t[80];int M1, M2, st1[64], st2[64];bool has_train[512][64][2];int dp[51... 阅读全文
posted @ 2015-03-31 17:58 Popco 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 这道题有点像翻煎饼那题,方法不限,只要次数在9^6之内即可。 从前到后依此选择数,最多只需要两次就可以将每个数放到正确位置。 #include using namespace std;int a[10240];void change(const int l, const int r){ f... 阅读全文
posted @ 2015-03-25 14:32 Popco 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 这题用了冒泡排序的思想,不过紫书上的描述有误,建议参考原题。 #include using namespace std;deque a;vector res;bool is_order(){ for (int i = 1; i != a.size(); ++i) if (a[i] > n, n... 阅读全文
posted @ 2015-03-19 17:26 Popco 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 不想说这题有多么水了,最简单的DFS题了,但是!我花了N天在杭电用G++交了20多遍一直超时,最后改C++交过了!! 这是什么情况!!无语了!! #define _CRT_SECURE_NO_WARNINGS#include #include #include const int maxn = ... 阅读全文
posted @ 2015-03-17 23:16 Popco 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 这题关键就是递推公式,注意紫书上推的c(k)那里貌似有点问题,应该是c(k-1)。 另外2^k方的计算可以用1using namespace std;using LL = long long;LL C[32] = {1};LL g(LL k, LL i){ if(i (1LL= (1LL... 阅读全文
posted @ 2015-03-15 15:52 Popco 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 最水的题,挺简单,用数学做的,刚开始判断负数写成了-1失误超时了. #include using namespace std;int main(){ int n, kase = 0; while(cin >> n, n > 0) printf("Case %d: %d\... 阅读全文
posted @ 2015-03-14 15:16 Popco 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 循环遍历数组即可,注意临界条件的判断。 #include using namespace std;const int maxn = 102400;int p[maxn], q[maxn];int main(){ //freopen("in.txt", "r", stdin); int... 阅读全文
posted @ 2015-03-13 17:25 Popco 阅读(97) 评论(0) 推荐(0) 编辑
摘要: 这题算贪心中最简单的,属于背包问题吧,写的效率有点低,用数组加指针控制应该更好。 #include #include #include #include #include using namespace std;int main(){ int T; cin >> T; while(... 阅读全文
posted @ 2015-03-13 17:23 Popco 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point lo... 阅读全文
posted @ 2015-03-08 18:06 Popco 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。 #include #include #include using ... 阅读全文
posted @ 2015-03-06 11:41 Popco 阅读(115) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 9 下一页