上一页 1 ··· 42 43 44 45 46 47 48 49 50 ··· 66 下一页
摘要: 给定各种数量的硬币,求能够组合成多少种符合题意的组合数。代码如下:#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <iostream>#define MAXN 100000using namespace std;int N, M, dp[MAXN+5], p[105], n[105];void zobag(int x, int k){ int ans = 0; if (M>=k*p[x]) { for (int i = M 阅读全文
posted @ 2012-04-23 15:08 沐阳 阅读(282) 评论(0) 推荐(0) 编辑
摘要: 题义:给定一个不长于100的字符串,求输入完整个串的最少按键次数。思路:对于打完每一个字符后,保留其保留大写锁定和非大写的两种状态的最少按键次数即可,做题中竟然忘了在大写锁定的时候可以shift+alphabet可以打出小写。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#include <cctype>#include <algorithm>using namespace std;int dp[105][2]; // 零表示以小写结尾,1代表以大写结尾char s 阅读全文
posted @ 2012-04-21 09:45 沐阳 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 这题是一个二维背包的题目,刚开始并没有那样去做,只开了一维的空间来存储状态,结果很多的数据都没有跑过去。其实这题这样来问的话可能就明了很多了,求在指定的容忍值和指定的杀怪数下,求最大能够得到了经验数,可能我们马上就能想到二维背包,一维为杀怪数,二维为容忍值,在做一个完全背包,可惜这题问的是在满足升级情况下最大的容忍值,这其实也能够用上面构建的模型了解决。只要的求解的过程每次将得到的经验值与给定的N进行比较,如果超过了N,那么说明当前的方案能够触发升级,再将此时剩余的容忍值传递出来就可以了。总而言之,题目对攻击次数和容忍值进行了限制,那么我们就要对限制的量进行动态规划。代码如下:#include 阅读全文
posted @ 2012-04-21 08:06 沐阳 阅读(475) 评论(0) 推荐(0) 编辑
摘要: #include <cstdio>using namespace std;void print(char s, int size){ for (int i = 0; i < size-1; ++i) { for (int j = 1; j <= size+i; ++j) { if (j == size+i || j == size-i) { printf("%c", s); } else { printf(" "); } ... 阅读全文
posted @ 2012-04-19 20:57 沐阳 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 博客里面还有以前写的解题报告,表示没看懂。这里直接计算其没有被录取的概率,每次去小的值即可代码如下:#include <cstring>#include <cstdio>#include <cstdlib>#define MAXN 1005using namespace std;int N, M, s[MAXN];double p[MAXN], dp[10005];inline double min(double x, double y){ return x < y ? x : y;}void zobag(int x){ for (int i = N; 阅读全文
posted @ 2012-04-19 17:24 沐阳 阅读(285) 评论(0) 推荐(0) 编辑
摘要: #include <cstdlib>#include <cstring>#include <cstdio>#define MAXN 105using namespace std;int N, seq[MAXN][MAXN], dp[MAXN][MAXN];inline int max(int x, int y){ return x > y ? x : y;}int DP(){ for (int i = 1; i <= N; ++i) { dp[N][i] = seq[N][i]; } for (int i = N-1; i >= 1; -- 阅读全文
posted @ 2012-04-19 17:00 沐阳 阅读(294) 评论(0) 推荐(0) 编辑
摘要: 通过给定的数据组成可及的状态。最后再中中间开始遍历所有可及的状态。就是一个完全背包,用二进制优化。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#define MAXN 250005using namespace std;int N, dp[MAXN], p[55], n[55], total;void zobag(int x) { for (int i = total>>1; i >= x; --i) { if (dp[i-x]) { dp[i] = 1; } ... 阅读全文
posted @ 2012-04-19 16:45 沐阳 阅读(268) 评论(0) 推荐(0) 编辑
摘要: 简单动态规划,将长方体分解成六个,然后二重排序后,DP即可。对于当前方块,选择前面的能够放置的方块的最大值加上本身的高度。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>#define MAXN 200using namespace std;// 对于每个长方体,有三种不同的方法。int N, dp[MAXN];struct Node{ int x, y, z;}e[MAXN];inline int max(int x, int y){ r 阅读全文
posted @ 2012-04-18 22:42 沐阳 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 01背包最裸模板题#include <cstdlib>#include <cstring>#include <cstdio>#define MAXN 1005using namespace std;int N, V, p[MAXN], v[MAXN], dp[MAXN];inline int max(int x, int y){ return x > y ? x : y;}void zobag(int x){ for (int i = V; i >= v[x]; --i) { dp[i] = max(dp[i], dp[i-v[x]]+p[x]) 阅读全文
posted @ 2012-04-18 17:11 沐阳 阅读(160) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1505自己写的屌丝代码:#include <cstdlib>#include <cstring>#include <cstdio>#define MAXN 1050using namespace std;int N, M, u[MAXN][MAXN], l[MAXN][MAXN], G[MAXN][MAXN];inline int max(int x, int y){ return x > y ? x : y;}inline int min(int x, int y) 阅读全文
posted @ 2012-04-18 16:37 沐阳 阅读(581) 评论(0) 推荐(0) 编辑
上一页 1 ··· 42 43 44 45 46 47 48 49 50 ··· 66 下一页