寒假第七周 2.22 --- 2.28
2016-02-22 08:06
337 查看
新的一周^w^
2.22
cf 628d Magic Numbers
自己的状态定义错了
应该是 dp[i][j][0] 前 i 位 有一位是小于的,dp[i][j][1] 前 i 位都是相同的
View Code
2.22
cf 628d Magic Numbers
自己的状态定义错了
应该是 dp[i][j][0] 前 i 位 有一位是小于的,dp[i][j][1] 前 i 位都是相同的
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<map> using namespace std; typedef long long LL; const int maxn = 1e5+5; int dp[maxn],pre[maxn],n,m; char s[maxn]; char str[maxn][1005]; int mod[2] = {998244353,1000000007}; int base[2] = {217,31}; LL now[2]; LL hehe[1005]; map<pair<LL,LL>,int> h; void print(int x){ if(pre[x] == -1) return; int len = strlen(str[pre[x]]); print(x - len); printf("%s ",str[pre[x]]); } int main(){ while(scanf("%d",&n) != EOF){ scanf("%s",s); scanf("%d",&m); h.clear(); for(int i =0;i < m;i++){ scanf("%s",str[i]); memset(now,0,sizeof(now)); int len = strlen(str[i]); for(int k = 0;k < 2;k++){ for(int j = 0;j < len;j++){ char c = str[i][j]; if(c >= 'A' && c <= 'Z') c += 'a'-'A'; now[k] = (now[k]*base[k]+c)%mod[k]; } } h[make_pair(now[0],now[1])] = i; } memset(dp,0,sizeof(dp)); memset(pre,-1,sizeof(pre)); dp[0] = 1; for(int i = 0;i < n;i++){ memset(now,0,sizeof(now)); for(int j = i;j >= max(0,i-1000);j--){ for(int k = 0;k < 2;k++) now[k] = (now[k]*base[k]+s[j])%mod[k]; if(dp[j] && h.find(make_pair(now[0],now[1])) != h.end()){ // printf("i = %d j = %d\n",i,j); dp[i+1] = 1; pre[i+1] = h[make_pair(now[0],now[1])]; } } } print(n); printf("\n"); } return 0; }
View Code
相关文章推荐
- Web安全測试二步走
- SQL Server代理(9/12):理解作业和安全
- 一个存在三年的内核 bug 引发大量的容器系统出现网络故障
- 一个存在三年的内核 bug 引发大量的容器系统出现网络故障
- UVa 227, Puzzle
- mian( )函数查找(Windows下逆向分析)
- 《Linux优化之安全最小化6个思想》
- 第11期《梦想,一直在路上》2016年2月刊
- Android 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- OSChina 周一乱弹 ——取经之路才刚刚开始
- 同步异步5:任务提交中的同步异步
- HTML基础(CSS)
- LeetCode One Edit Distance
- 同步异步4:CDMA中的同步异步
- 34. Search for a Range
- Integer的源码分析
- MVC Controller return 格式之JsonResult、ContentResult、RedirectResult……
- iOS中的两种搜索方式UISearchDisplayController和UISearchController
- iOS中的两种搜索方式UISearchDisplayController和UISearchController
- iOS中的两种搜索方式UISearchDisplayController和UISearchController