HDU 2016.11.12 做题感想
细数一下这两天做过的值得总结的一些题Orz......
HDU 2571 简单dp,但是一开始WA了一发。原因很简单:没有考虑仔细。
如果指向该点的所有点权值都为负数,那就错了(我一开始默认初始值为0)
这是非常基础的典型DAG模型,好久不做,手明显生了……
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i)
#define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i)
#define for_edge(i,x) for(int i = H[x]; i; i = X[i]) #define LL long long
#define ULL unsigned long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define INF 1 << 30 const int N = + ;
const int M = + ;
const int Q = + ;
const int A = + ; int f[A][Q], c[A][Q];
int T;
int n, m; int main(){
#ifndef ONLINE_JUDGE
freopen("test.txt", "r", stdin);
freopen("test.out", "w", stdout);
#endif scanf("%d ", &T);
REP(Case, T){
scanf("%d %d ", &n, &m);
memset(f, , sizeof f);
rep(i, , n) rep(j, , m) scanf("%d ", &c[i][j]);
f[][] = c[][];
rep(i, , m){
int now = f[][i - ];
rep(j, , i >> ) if (i % j == ) now = max(now, f[][j]);
f[][i] = c[][i] + now;
} rep(i, , n) f[i][] = c[i][] + f[i - ][];
rep(i, , n) rep(j, , m){
int now = f[i][j - ];
rep(k, , j >> ) if (j % k == ) now = max(now, f[i][k]);
now = max(now, f[i - ][j]);
f[i][j] = c[i][j] + now;
}
//rep(i, 1, n){ rep(j, 1, m) printf("%d ", f[i][j]); putchar(10);}
printf("%d\n", f[n][m]);
} return ; }
还有就是记忆化搜索,很裸的一道题。 HDU1579
题目也说了大数据时直接递归会超时,所以除了记忆化搜索,别无选择。
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i)
#define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i)
#define for_edge(i,x) for(int i = H[x]; i; i = X[i]) #define LL long long
#define ULL unsigned long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define INF 1 << 30 const int N = + ;
const int M = + ;
const int Q = + ;
const int A = + ; int f[A][A][A];
int x, y, z; int cal(int x, int y, int z){
if (x <= || y <= || z <= ) return ;
if (x > || y > || z > ) return f[][][] = cal(, , );
if (f[x][y][z] != -) return f[x][y][z];
if (x < y && y < z) return f[x][y][z] = cal(x, y, z - ) + cal(x, y - , z - ) - cal(x, y - , z);
else return f[x][y][z] = cal(x - , y, z) + cal(x - , y - , z) + cal(x - , y, z - ) - cal(x - , y - , z - );
} int main(){
#ifndef ONLINE_JUDGE
freopen("test.txt", "r", stdin);
freopen("test.out", "w", stdout);
#endif memset(f, -, sizeof f);
while (~scanf("%d%d%d", &x, &y, &z)){
if (x == - && y == - && z == -) break;
printf("w(%d, %d, %d) = %d\n", x, y, z, cal(x, y, z));
} return ; }
还有一道并查集裸题……HDU1232
直接YY一个就A了……
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i)
#define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i)
#define for_edge(i,x) for(int i = H[x]; i; i = X[i]) #define LL long long
#define ULL unsigned long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define INF 1 << 30 const int N = + ;
const int M = + ;
const int Q = + ;
const int A = + ; int f[N];
int n, m;
int x, y; int getfather(int x){ return f[x] ? f[x] = getfather(f[x]) : x;} int main(){
#ifndef ONLINE_JUDGE
freopen("test.txt", "r", stdin);
freopen("test.out", "w", stdout);
#endif while (~scanf("%d", &n), n){
scanf("%d", &m);
memset(f, , sizeof f);
while (m--){
scanf("%d%d", &x, &y);
int fa = getfather(x), fb = getfather(y);
if (fa != fb) f[fa] = fb;
} int ans = ;
rep(i, , n - ) rep(j, i + , n){
int fa = getfather(i), fb = getfather(j);
if (fa != fb){
f[fa] = fb;
++ans;
}
if (ans >= n) break;
} printf("%d\n", ans);
} return ; }
剩下的一些水题都不好意思拿出来……之后要加大难度了……
The End.
HDU 2016.11.12 做题感想的更多相关文章
- AtCoder Grand Contest 11~17 做题小记
原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-Grand-Contest-from-11-to-20.html UPD(2018-11-16): ...
- P2599 [ZJOI2009]取石子游戏 做题感想
题目链接 前言 发现自己三岁时的题目都不会做. 我发现我真的是菜得真实. 正文 神仙构造,分讨题. 不敢说有构造,但是分讨我只服这道题. 看上去像是一个类似 \(Nim\) 游戏的变种,经过不断猜测结 ...
- 2016/1/12 第一题 输出 i 出现次数 第二题 用for循环和if条件句去除字符串中空格 第三题不用endwith 实现尾端字符查询
import java.util.Scanner; public class Number { private static Object i; /* *第一题 mingrikejijavabu中字符 ...
- P6622 信号传递 做题感想
题目链接 前言 在这里分享两种的做法. 一种是我第一直觉的 模拟退火.(也就是骗分) 还有一种是看题解才搞懂的神仙折半搜索加上 dp . 模拟退火 众所周知,模拟退火 是我这种没脑子选手用来骗分的好算 ...
- NOIP2016考前做题(口胡)记录
NOIP以前可能会持续更新 写在前面 NOIP好像马上就要到了,感觉在校内训练里面经常被虐有一种要滚粗的感觉(雾.不管是普及组还是提高组,我都参加了好几年了,结果一个省一都没有,今年如果还没有的话感觉 ...
- NOIp 11.11/12
最后一场比较正式的NOIp模拟赛,写一发小总结.题目没什么好说的,大部分很简单,先贴一下代码. 1111 T1 //string //by Cydiater //2016.11.11 #include ...
- U3D笔记11:47 2016/11/30-15:15 2016/12/19
11:47 2016/11/30Before you can load a level you have to add it to the list of levels used in the gam ...
- 2016年12月16日 星期五 --出埃及记 Exodus 21:11
2016年12月16日 星期五 --出埃及记 Exodus 21:11 If he does not provide her with these three things, she is to go ...
- 2016年12月11日 星期日 --出埃及记 Exodus 21:6
2016年12月11日 星期日 --出埃及记 Exodus 21:6 then his master must take him before the judges. He shall take hi ...
随机推荐
- ARC下,不显式指定任何属性关键字时,默认的关键字都有哪些
1.对应基本数据类型默认关键字是 atomic,readwrite,assign 2.对于普通的 Objective-C 对象 atomic,readwrite,strong
- react事件处理及动态样式添加
多数据的事件绑定,循环数据来进行绑定.如下方式就是循环绑定事件的基本代码: this.state.lists.map(function(value,index,array){//代码片段}.bind( ...
- Django笔记 —— 模板
最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...
- cocos2d安装
cocos2d引擎要求Python 2 为2.6 以上版本,Python 3 为3.3以上版本 cocos2d引擎安装支持pip安装,安装指令如下: pip install cocos2d
- 编译Code::Blocks源码 with MinGW on Win
Build Code::Blocks源码 ---By 狂徒归来 CodeBlocks是一款非常优秀的IDE !可惜的是没有64位的版本,而且本来是轻量级别的IDE就应该够轻,能够像记事本工具一样,迅速 ...
- 201621123033 《Java程序设计》第8周学习总结
第八次作业 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 首先调 ...
- hdu 1195 Open the Lock (BFS)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 解决某些PC站在手机端宽度显示不正常的问题
可以打开控制台查看html标签的宽度,发现不是当前屏幕的宽度,更改下宽度即可:用js控制下,上代码 document.getElementsByTagName('html')[0].style.wid ...
- java中的URLEncoder.encode对应JS中用decodeURIComponent,js和java编码,解码
用get请求传中文,经常搞到乱码,这几天搞搞这个东西,总结一下,以方便以后处理这类的问题. Java代码中的URLEncoder.encode方法和JS的encodeURIComponent功能差不多 ...
- Myeclipse中生成subscription code的代码
//代码如下: package com.qls.AddingMethodsToAnEnum; import java.io.*; public class MyEclipseGen { private ...