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 ...
随机推荐
- Jmeter mysql性能测试
一:首先建立jdbc connection configuration,设置参数如图 1.variable name 参数名称,与后面的sample中设置的variable name一致.含义为:通过 ...
- Python全栈工程师(Linux基本操作)
ParisGabriel Python 入门基础 Linux :Ubuntu操作系统 首先我们说的是Linux操作系统常用的快捷键以及终端命令 一. VMware ...
- 孤荷凌寒自学python第六十天在windows10上搭建本地Mongodb数据服务
孤荷凌寒自学python第六十天在windows10上找搭建本地Mongodb数据服务 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第六天.成功在本地搭建了windows ...
- glance参数
Image service property keys https://docs.openstack.org/python-glanceclient/latest/cli/property-keys. ...
- Codeforces 1088E 树形dp+思维
比赛的时候看到题意没多想就放弃了.结果最后D也没做出来,还掉分了,所以还是题目做的太少,人太菜. 回到正题: 题意:一棵树,点带权值,然后求k个子连通块,使得k个连通块内所有的点权值相加作为分子除以k ...
- 决策树之CART算法
顾名思义,CART算法(classification and regression tree)分类和回归算法,是一种应用广泛的决策树学习方法,既然是一种决策树学习方法,必然也满足决策树的几大步骤,即: ...
- 第二阶段团队冲刺-four
昨天: 绘制logo. 今天: 用servlet完成名单打印功能. 遇到的问题: servlet中的获得的路径不是想要的.
- java窗口程序初学组件小总结
容器(可以放组件)JPanel默认的布局管理器是FlowLayout:JPanel panel=new JPanel(); 按钮JButton(可以为汉字 也可以是图片):JButton button ...
- c#中RadioButtonList选中后不整体刷新页面保持选中状态
c#中用asp的RadioButtonList控件总会遇到选中了,然后跟着就刷新整体页面,又变为没有选中状态. <%@ Page Language="C#" AutoEven ...
- PHP的几种遍历方法
PHP常用的遍历方法有三种,foreach,for,list()/each()和while,这三种方法中效率最高的是使用foreach语句遍历数组 一.使用for语句循环遍历数组 值得大家注意的是使用 ...