[CF Gym 100372B] Sergey and a pattern
来源:互联网 发布:尼古拉斯赵四 知乎 编辑:程序博客网 时间:2024/06/06 01:06
题意
给出一个初始序列
1 从
2 弹栈,将栈顶放到
长度至多16
题解
将f[压栈次数][弹栈次数][状态]
然后dp
代码
#include <cstdio>#define maxn 16#define maxs (1<<16)#define mod 1000000007LLint n, a[maxn+1], b[maxn+1], f[maxn+1][maxn+1][maxs] = {0};/// f[in][out][exist]int main() { int i, j, s, k; scanf("%d", &n); for (i = 1; i <= n; i ++ ) scanf("%d", &a[i]); for (i = 1; i <= n; i ++ ) scanf("%d", &b[i]); /// build array b from array a ! f[0][0][0] = 1; for (i = 0; i <= n; i ++ ) for (j = 0; j <= i; j ++ ) for (s = (1<<i)-1; s >= 0; s -- ) { if (!f[i][j][s]) continue; if (i < n) (f[i+1][j][s|(1<<i)] += f[i][j][s]) %= mod; if (!s) continue; for (k = i; !((1<<k-1)&s); k -- ); if (b[j+1]!=-1 && a[k]!=b[j+1]) continue; (f[i][j+1][s^(1<<k-1)] += f[i][j][s]) %= mod; } printf("%d\n", f[n][n][0]);//while(1); return 0;}
0 0
- [CF Gym 100372B] Sergey and a pattern
- [CF Gym 100372C] Sergey and array
- [CF Gym 100372E] Sergey’s game
- CF 739B - Alyona and a tree
- CF GYM 100741 A Queries
- CF(#294 div2):D. A and B and Interesting Substrings
- CF#421 A. Mister B and Book Reading(模拟)
- cf Gym
- CF GYM 100548 Built with Qinghuai and Ari Factor(2014ACM西安现场赛Problem A)
- 【打CF,学算法——一星级】Gym 100548A Built with Qinghuai and Ari Factor (Asia Xian)
- CF B. Stadium and Games
- (CF)B. Sereja and Contests
- cf:B Kefa and Company
- CF--B. Wilbur and Array
- cf B. Wilbur and Array
- cf--B - Anatoly and Cockroaches
- 前缀和STL CF D A and B and Interesting Substrings
- CF 294 div2 D. A and B and Interesting Substrings (hash)
- [爆栈热门 iOS 问题] 让 UILabel 顶端对齐
- ld
- jpa
- Nginx的反向代理和负载均衡
- 蓝桥杯---操作格子 (线段树)
- [CF Gym 100372B] Sergey and a pattern
- springmvc和mybatis整合-查询用户列表
- [源码]使用QSS的扁平化风格的成绩管理系统
- PHP基础之运算符(四)连接运算符、赋值运算符、三元表达式
- PHP基础之运算符(五)【短路特性】
- java写个纪念日
- 20 semaphore 2
- 【C语言学习笔记】初识GCC编译器
- HEVC MarginX MarginY的理解