摘要:bzoj第一题,ctsc2001. 黑书上的递归例题,我们定义time()函数,递归求解即可。 这个题用到了一个小技巧:可以使用枚举来搞算法。 include include include using namespace std; int n, m; int p(int a, int b) { i
阅读全文
摘要:``` include using namespace std; int d[100], w[100], s, n; int dp[100][100][3]; int main() { scanf("%d%d", &n, &s); for (int i = 1; i = 1; i ) for (in
阅读全文
摘要:``` include using namespace std; const int maxn = 301; std::vector son[maxn]; vector G[maxn]; int deep[maxn], size[maxn]; vector dep[maxn]; int vis[ma
阅读全文
摘要:``` include define inf 1000000000 define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch==' ')f= 1;ch
阅读全文
摘要:``` include define searchnext(x, y) y == 9 ? search(x + 1, 1) : search(x, y + 1) using namespace std; long long ans = 0; int a[10][10]; void search(in
阅读全文
摘要:打了一个最大生成树+dfs,60分成功tle include using namespace std; const int maxn = 10005; const int maxm = 50005; int n, m, cnt = 0; struct edge { int from, to, val
阅读全文
摘要:此题很容易写出方程,由以前的知识可以迁移得,本题可以用完全背包的方法进行优化,使用滚动数组即可得到答案。 //莫名奇妙60分。不知道什么细节出了错。 include using namespace std; const int maxn = 10005; int main() { // freope
阅读全文
摘要:题意 给出一段字符串和一个字典,把字符串划分为n个连续的子串,求一种最优的划分方式使字符串所含单词数最大。(详见NOIp2001) 思路 这个题是一个很典型的线性dp,难点主要在预处理上。 理解题意后,我们不难写出状态转移方程: f[i][j] = max(f[k][j 1] + calc(k+1,
阅读全文
摘要:``` include using namespace std; const int maxn = 100005; int head1[maxn], head2[maxn], maxx[maxn], minn[maxn]; bool in1[maxn], in2[maxn]; int value[m
阅读全文
摘要:概述 首先,这是一道好题,这道题既考查了图论的dfs知识,又考察了区间贪心问题中很典型的区间覆盖问题,着实是一道好题。 大概思路说明 我们观察到,只有第一行可以放水库,而第一行在哪里放水库的结果就是直接导致最后一行某些点被覆盖。所以我们 只需要找到第一行水库与最后一行被覆盖的关系 即可完成决策,中间
阅读全文
摘要:开始写了一个O(n3)的算法,只得了60,后来思考(找题解),得到了一个O(nk)的算法 其实就是一种预处理的思想,对于每一个客栈而言,只要我们预处理出他前面可以匹配的客栈数量,就可以了。 所以我们记录a[i]为颜色i的数量,b[i]为颜色i可匹配的数量 输入每一个客栈,我们都更新a[i],同时如果
阅读全文
摘要:``` include using namespace std; const int maxn = 105; struct node { int situation, yuzhi; }ns[maxn]; std::vector g[maxn]; int main() { int n, p; cin
阅读全文
摘要:``` include using namespace std; const int maxn = 1005; int main() { freopen("input.in", "r", stdin); char mi[maxn], key[105]; scanf("%s%s", key, mi);
阅读全文
摘要:思路:前缀和, c表示对于当前的middle, 前缀和 include using namespace std; const int maxn = 1e6+1; int n, m, now, r[maxn], d[maxn], s[maxn], t[maxn], c[maxn]; bool chec
阅读全文
摘要:``` include using namespace std; int b[4]; int a[3]; int calc(int a, int b, int c) { if(c == 1) return a + b; else if(c == 2) return a b; else if(c ==
阅读全文
摘要:``` include using namespace std; const int maxn = 10005; set to[maxn]; queue q;int s, t;int n, m;set to2[maxn]; int dist[maxn], used[maxn], dist2[maxn
阅读全文
摘要:``` include using namespace std; const int maxn = 200005; vector son[maxn]; int v[maxn], s[maxn], w[maxn]; int main() { freopen("input.in", "r", stdin
阅读全文
摘要:30分做法,暴力枚举: include using namespace std; const int maxn = 400; int n, m; int a[maxn], b[maxn]; //a:格子,b:卡牌 void read() { cin n m; for(int i = 0; i a[i
阅读全文
摘要:开始定义状态f[i][j][k]为[i,j)区间插入k个括号,使用记忆化搜索,但是成功爆栈,得到4个mle include using namespace std; const int maxn = 45; int n, k, len; long long f[maxn][maxn][maxn];
阅读全文
摘要:``` #include using namespace std; struct BigInteger { static const int BASE = 100000000; static const int WIDTH = 8; vector s; BigInteger(long long num = 0) { *this = num; } // 构造函数 BigInte...
阅读全文
摘要:这道题没有一个比较详细的题解,我来提供一份。 首先我们可以知道,反转区间的顺序对结果没有影响,而且一个区间如果翻转两次以上是没有意义的,所以,问题就变成了求哪些区间需要反转。 我们枚举k。对于每一个k,我们设计一个calc函数来判断k的操作次数。 显然的,我们可以设计出一种方法,就是每一次都检查最左
阅读全文
摘要:状态定义是dp中非常重要的,可以直接影响到效率,如此题,第一种思路是: include using namespace std; const int maxn = 100005; struct node { int high, value; bool operator value pf, pg; f
阅读全文
摘要:``` include using namespace std; const int num[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int dp[2000]; int solve(int k) { if(dp[k]) return dp[k]; if(k n; n
阅读全文
摘要:水题,记忆化搜索,队列bfs均可 我们定义f[i][j]为到(i, j)的最长路径。然后就不难得出状态转移方程,然后使用无脑dfs,或者有脑递推都是可以的。 include using namespace std; const int maxn = 105; const int dx[] = {0,
阅读全文
摘要:水题 include using namespace std; const int maxn = 105; int main(int argc, char const argv[]) { int n; cin n; int high[maxn]; for(int i = 1; i high[i];
阅读全文
摘要:``` include using namespace std; const int maxn = 10005; int main(int argc, char const argv[]) { int a[maxn]; int n; cin n; priority_queue, greater q;
阅读全文
摘要:贪心,水题 include using namespace std; const int maxn = 1000000; struct house { int s; int a; int value; }hs[maxn]; bool operator n; for(int i = 1; i hs[i
阅读全文
摘要:http://www.cnblogs.com/zbtrs/p/5762788.html http://blog.csdn.net/loi_yzs/article/details/52795093 都是不错的解析,我在这里就不多说了 include using namespace std; const
阅读全文