Shut the Box HDU4212
来源:互联网 发布:公司网络微信被屏蔽 编辑:程序博客网 时间:2024/06/04 23:33
http://acm.hdu.edu.cn/showproblem.php?pid=4212
论文写烦了,水了一道很水的状压DP,状态很稀疏用map搞下,预处理很关键。
#include <cstdio>#include <cstdlib>#include <iostream>#include <cstring>#include <map>#include <string>#include <algorithm>#include <utility>#include <list>#include <fstream>#include <cctype>#include <vector>#include <cmath>#include <climits>#include <ctime>using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef unsigned UN;typedef pair<int, int> PAIR;typedef multimap<int, int> MMAP;typedef long double LF;const int MAXN(300010);const int MAXM(20010);const int MAXE(210);const int MAXK(6);const int HSIZE(313131);const int SIGMA_SIZE(26);const int MAXH(19);const int INFI((INT_MAX-1) >> 1);const ULL BASE(31);const LL LIM(1e13);const int INV(-10000);const int MOD(1000000007);const double EPS(1e-7);const LF PI(acos(-1.0));template<typename T> inline bool checkmax(T &a, T b){if(b > a) { a = b; return true;} return false;}template<typename T> inline bool checkmin(T &a, T b){if(b < a) { a = b; return true;} return false;}template<typename T> inline T ABS(T a){return a < 0? -a: a;}template<typename T> inline bool EZ(T a){return ABS(a) < EPS;}struct HASH_MAP{int first[HSIZE];int state[MAXN], val[MAXN], next[MAXN], size;void init(){memset(first, -1, sizeof(first));size = 0;}void insert(int ts, int tv){int h = ts%HSIZE;for(int i = first[h]; ~i; i = next[i])if(ts == state[i])return;state[size] = ts;val[size] = tv;next[size] = first[h];first[h] = size++;}} hm[2], *cur, *last;vector<PAIR> vec[23][23];void dfs(int dep, int st, int v, int cnt){if(v > 22) return;if(v > 0) vec[dep-1][v].push_back(PAIR(st, cnt));if(dep == 23) return;dfs(dep+1, st, v, cnt);dfs(dep+1, st|(1 << dep), v+dep, cnt+1);}int main(){dfs(1, 0, 0, 0);int N, T, n_case(0);while(~scanf("%d%d", &N, &T), N+T){vector<PAIR> *vp = vec[N];cur = hm;last = hm+1;last->init();last->insert(0, 0);int ans = 0;int temp;for(int i = 0; i < T; ++i){scanf("%d", &temp);cur->init();for(vector<PAIR>::iterator it = vp[temp].begin(); it != vp[temp].end(); ++it){int sz = last->size;for(int j = 0; j < sz; ++j)if((last->state[j]&it->first) == 0){int tv = last->val[j]+it->second;checkmax(ans, tv);cur->insert(last->state[j]+it->first, tv);}}swap(cur, last);}printf("Game %d: %d\n", ++n_case, ans);}return 0;}
0 0
- Shut the Box HDU4212
- CSU1855:Shut the Box(二进制状态压缩+BFS)
- 393. The cat shut its eyes when stealing. 掩耳盗铃
- The CSS Box Model
- out of the box
- Moving the Search Box
- The CSS Box Model
- 10215 - The Largest/Smallest Box ...
- UVA 10215 - The LargestSmallest Box ...
- COM:The Open Dialog Box
- Error -27791: Server "" has shut down the connection prematurely的一个解决办法
- [转]Error -27791: Server "" has shut down the connection prematurely的一个解决办法
- 121.After performing a clean shut down of the database instance for maintenance, you mount the datab
- 123.You used the IMMEDIATE option to shut down your database instance. Consider the steps that may o
- Think Outside the Box: 一道原创智力题
- Add check box into the datatable
- bfs hdu 1732 push the box
- [uva] 10215 - The Largest/Smallest Box ...
- Lagrange插值公式
- 培养终身阅读习惯的12种方法
- 链表插入(线性表)
- 第三周作业
- sicilyOJ 11中大预选赛 D Minimum Labeled Spanning Tree
- Shut the Box HDU4212
- 删除线性表节点(线性表)
- 汇编语言 课程设计2 之时间设置改进篇
- 【四圣龙神录的编程教室】第19章、给敌机加上消灭特效吧
- 海量数据处理常用数据结构及方法
- C++学习之构造函数的理解--模板形式的构造函数不会遮掩编译器生成的默认构造函数
- 节点插入(线性表)
- 一步步学习微软InfoPath2010和SP2010--第十二章节--管理和监控InfoPath Form Services(IPFS)
- Linux Socket TCP通信