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 ...
随机推荐
- 梆梆加固还原DEX文件
0x01 先说总结: 参照https://www.cnblogs.com/jiaoxiake/p/6818786.html 最后说的步骤, 参考:https://www.52pojie.cn/thre ...
- 用JAX-WS在Tomcat中发布WebService
JDK中已经内置了Webservice发布,不过要用Tomcat等Web服务器发布WebService,还需要用第三方Webservice框架.Axis2和CXF是目前最流行的Webservice框架 ...
- SecureCRT自动登录跳板机/堡垒机并连接目标机器
公司登录目标服务器,需要先登录跳板机(堡垒机),然后再登录目标机器,一共需要4.5步. MAC或LINUX机器可以写.SH脚本,那WINDOWS有没有一键登陆的方法呢? 常用的SecureCRT工具就 ...
- JSP/Servlet Web 学习笔记 DayThree
JSP内置对象 使用JSP语法可以存取这些内置对象来执行JSP网页的Servlet环境相互作用.内置对象其实是由特定的Java类所产生的.每一种内置对象都映射到一个特定的Java类或者端口,在服务器运 ...
- 哈希URAL 1941 - Scary Martian Word
A - Scary Martian Word Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- macOS Mojave 深色模式
macOS Mojave 深色模式 mac 关闭 深色模式 https://support.apple.com/zh-cn/HT208976 https://www.apple.com/cn/maco ...
- MySQL常用客户端 命令
登录MySQL mysql -h localhost -uroot -p 授权指定用户访问指定数据库 GRANT ALL ON cookbook.* TO 'cbuser'@'localhost' I ...
- Android Studio使用过程中常见问题及解决方案
熟悉Android的童鞋应该对Android Studio都不陌生.Android编程有两个常用的开发环境,分别是Android Studio和Eclipse,之前使用比较多的是Eclipse,而现在 ...
- 省选算法学习-回文自动机 && 回文树
前置知识 首先你得会manacher,并理解manacher为什么是对的(不用理解为什么它是$O(n)$,这个大概记住就好了,不过理解了更方便做$PAM$的题) 什么是回文自动机? 回文自动机(Pal ...
- BZOJ1086 [SCOI2005]王室联邦 【dfs + 贪心】
题目 "余"人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成 员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两 ...