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 ...
随机推荐
- 成员变量和属性区别(@property那点事儿)
历史由来: 接触iOS的人都知道,@property声明的属性默认会生成一个_类型的成员变量,同时也会生成setter/getter方法. 但这只是在iOS5之后,苹果推出的一个新机制.看老代码时,经 ...
- 踩到Framework7 Photo Browser 的一个坑
最近在做的项目用了Framework7前端框架,功能确实比较强大!但这两天遇到一个坑,希望我的这点收获能给遇到这个问题的朋友一点帮助. 在使用Photo Browser 的时候,图片下方想放一个“点赞 ...
- 【Count Complete Tree Nodes】cpp
题目: Given a complete binary tree, count the number of nodes. Definition of a complete binary tree fr ...
- 【Soft-Margin Support Vector Machine】林轩田机器学习技术
Hard-Margin的约束太强了:要求必须把所有点都分开.这样就可能带来overfiiting,把noise也当成正确的样本点了. Hard-Margin有些“学习洁癖”,如何克服这种学习洁癖呢? ...
- 最短路径(Floyd法)
最短路径法: 算法的主要思想是:单独一条边的路径也不一定是最佳路径. 从任意一条单边路径开始.所有两点之间的距离是边的权的和,(如果两点之间没有边相连, 则为无穷大). 对于每一对顶点 u 和 v,看 ...
- 转:Redis设置认证密码 Redis使用认证密码登录 在Redis集群中使用认证密码
Redis默认配置是不需要密码认证的,也就是说只要连接的Redis服务器的host和port正确,就可以连接使用.这在安全性上会有一定的问题,所以需要启用Redis的认证密码,增加Redis服务器的安 ...
- serial console
适用于: agent_ipmitool_socat pxe_ipmitool_socat 修改driver方式:更换ironic node的driver类型 yum install -y socat ...
- 以太访solidity常用的函数有哪些
以太坊:什么是ERC20标准? 不以规矩,不能成方圆 许多人应该都听过 代码即法律(Code Is Law),因为程序写完了,无论执行多少次都会得到同样的结果,除非有外界因素的干扰.在多人协作的过程中 ...
- Actiivity 生命周期
Actiivity 生命周期,如下图所示: onCreate onStart (onRestarted) onResume onPaused(to onResume(User navigates to ...
- selenium webdriver——JavaScript警告窗处理
在WebDriver中处理JavaScript所生成的alert.confirm以及prompt,具体方法是使用switch_to_alert()方法定位到alert.confirm以及 prompt ...