sgu 225 分类: sgu 2015-06-15 19:24 16人阅读 评论(0) 收藏
2015-06-15 19:24
411 查看
状压DP,并没有加什么优化。。。
结果发现MLE了,蛤蛤。
你真的以为上面的代码能过吗?
还是太年轻了。。。
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> const int maxn = 15, sz = 10; struct Trans { int p1,p2,p3,cnt; Trans(){} Trans(int p1,int p2,int p3,int cnt):p1(p1),p2(p2),p3(p3),cnt(cnt){} }; int n, k; int tl; Trans ts[1<<(sz<<1)]; long long f[2][sz*sz+1][1<<sz][1<<sz]; long long ans[sz*sz+1]; int flag; #define STUS1 p1|(i*(1<<col)) #define STUS2 p2|(j*(1<<col)) #define STUS3 p3|(p*(1<<col)) void DFS0(int col,int p1,int p2,int cnt) { if(col == n) f[flag][cnt][p1][p2] = 1; else { int t1 = 0, t2 = 0; if(col < 2 || !(p2&(1<<(col-2)))) t1 = 1; if(col < 2 || !(p1&(1<<(col-2)))) t2 = 1; for(int i = 0; i <= t1; i++) for(int j = 0; j <= t2; j++) DFS0(col+1, STUS1, STUS2, cnt+i+j); } } void DFS(int col,int p1,int p2,int p3,int cnt) { if(col == n) ts[++tl] = Trans(p1,p2,p3,cnt); else { int t1 = 0, t2 = 0, t3 = 0; if(col < 2 || !(p2&(1<<(col-2)))) if(col < 1 || !(p3&(1<<(col-1)))) t1 = 1; if(col < 2 || !(p1&(1<<(col-2)))) if(col < 2 || !(p3&(1<<(col-2)))) t2 = 1; if(col < 1 || !(p1&(1<<(col-1)))) if(col < 2 || !(p2&(1<<(col-2)))) t3 = 1; for(int i = 0; i <= t1; i++) for(int j = 0; j <= t2; j++) for(int p = 0; p <= t3; p++) DFS(col+1, STUS1, STUS2, STUS3, cnt+p); } } #undef STUS1 #undef STUS2 #undef STUS3 void DP() { for(int i = 3; i <= n; i++) { flag ^= 1; for(int j = 1; j <= tl; j++) for(int p = ts[j].cnt; p <= k; p++) f[flag][p][ts[j].p2][ts[j].p3] += f[flag^1][p-ts[j].cnt][ts[j].p1][ts[j].p2]; for(int p = 0; p <= k; p++) for(int j = 1; j <= tl; j++) f[flag^1][p][ts[j].p1][ts[j].p2] = 0; } for(int p = 0; p <= k; p++) for(int j = 0; j < (1<<n); j++) for(int i = 0; i < (1<<n); i++) ans[p] += f[flag][p][i][j]; } int main() { #ifndef ONLINE_JUDGE freopen("sgu225.in","r",stdin); freopen("sgu225.out","w",stdout); #endif std::cin >> n >> k; DFS0(0,0,0,0), DFS(0,0,0,0,0), DP(); std::cout << ans[k]; // for(int i = 0; i <= k; i++) // std::cout << ans[i] << "LL,"; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
结果发现MLE了,蛤蛤。
你真的以为上面的代码能过吗?
还是太年轻了。。。
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> int n, k; long long list[15][110] = { {0}, {1,1}, {1,4,6,4,1}, {1,9,28,36,18,2,0,0,0,0}, {1,16,96,276,412,340,170,48,6,0,0,0,0,0,0,0,0}, {1,25,252,1360,4436,9386,13384,12996,8526,3679,994,158,15,1,0,0,0,0,0,0,0,0,0,0,0,0}, {1,36,550,4752,26133,97580,257318,491140,688946,716804,556274,323476,141969,47684,12488,2560,393,40,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,49,1056,13340,111066,649476,2774728,8891854,21773953,41310504,61412928,72304650,68233368,52400729,33376132,18001362,8363763,3374053,1178064,351592,87913,17910,2858,336,26,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1LL,64LL,1848LL,32084LL,376560LL,3184708LL,20202298LL,98796304LL,379978716LL,1167053680LL,2897726604LL,5876860140LL,9825415557LL,13660238780LL,15932672964LL,15737653004LL,13304668385LL,9742722088LL,6260518246LL,3574590840LL,1830733371LL,844203844LL,349524138LL,128874944LL,41833846LL,11792736LL,2840224LL,572432LL,93840LL,12004LL,1122LL,68LL,2LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL}, {1LL,81LL,3016LL,68796LL,1080942LL,12472084LL,110018552LL,762775440LL,4241252429LL,19206532478LL,71707869632LL,222946143752LL,582155146204LL,1286247689414LL,2421159140764LL,3908273840366LL,5446391581062LL,6599640204257LL,7010436668992LL,6589213734278LL,5537849837497LL,4207779106033LL,2920161348852LL,1865346129716LL,1101125592067LL,600730512987LL,302041066250LL,139345014744LL,58692638521LL,22451454400LL,7755194754LL,2403337080LL,663103709LL,161373907LL,34237130LL,6238414LL,957145LL,120334LL,11914LL,872LL,42LL,1LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL}, {1LL,100LL,4662LL,135040LL,2732909LL,41199404LL,481719518LL,4491423916LL,34075586550LL,213628255072LL,1120204619108LL,4961681221524LL,18715619717199LL,60541371615660LL,168976761361446LL,409191804533576LL,864172675710439LL,1599730843649564LL,2609262108838924LL,3770687313420780LL,4857550050070531LL,5616928666465104LL,5874943705896600LL,5604501518609804LL,4917655076255841LL,3999855946779732LL,3034690618677388LL,2156485957257040LL,1437827591264317LL,899278231344296LL,526753407546620LL,288274613750624LL,146990556682887LL,69626509814580LL,30542906352994LL,12366448408056LL,4604442057431LL,1569983914256LL,487876545370LL,137395261280LL,34831261750LL,7884855000LL,1578162590LL,275861904LL,41455966LL,5246412LL,543534LL,44244LL,2652LL,104LL,2LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL,0LL} }; int main() { #ifndef ONLINE_JUDGE freopen("sgu225.in","r",stdin); freopen("sgu225.out","w",stdout); #endif std::cin >> n >> k; std::cout << list [k]; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
相关文章推荐
- memcached老数据给踢
- OC基础:getter和setter,@public @protected @private
- 毕业五年决定你的一生
- OC基础:getter和setter,@public @protected @private 分类: ios学习 OC 2015-06-15 19:23 22人阅读 评论(0) 收藏
- 局域网
- UIView的Touch事件UIControlEvents详解
- sphinx和epel和centos的仇
- MATLAB中给图像加高斯噪声时imnoise的方差参数问题
- [hdu5254]BFS
- 多线程的web服务器
- SVN 代码 文件的删除及恢复
- Java集合系列-总体框架
- 异常:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
- C/C++ 在程序里执行SQL脚本
- 擅长排列的小明(C++next_permutation)
- LeetCode 82: Remove Duplicates from Sorted List II
- 【一些事晚报】小米动了乐视哪块奶酪?
- android手势动画
- 【BZOJ3572】【Hnoi2014】世界树 虚树
- Supervised Deep Learning with Auxiliary Networks