【FZU2190】非提的救赎【单调栈】
2015-05-04 22:06
337 查看
#include <iostream> #include <cstdio> #include <string> #include <string.h> #include <algorithm> using namespace std; const int MaxN=2010; long long dp[MaxN]; int up[MaxN]; int stack[MaxN]; int top; char s[MaxN]; long long ans; int push(int x) { while(top&&up[stack[top-1]]>=up[x]) --top; stack[top++]=x; if(top>1) return stack[top-2]; else return 0; } int main() { int N,M; int cou; while(~scanf("%d %d",&N,&M)) { ans=0; memset(up,0,sizeof up); while(N--) { scanf("%s",s+1); dp[0]=0; top=0; for(int i=1;i<=M;++i) { if(s[i]=='w') ++up[i]; else up[i]=0; cou=push(i); dp[i]=dp[cou]+(i-cou)*up[i]; ans+=dp[i]; } } printf("%lld\n",ans); } return 0; }
相关文章推荐
- fzu2190---非提的救赎 (单调栈)
- A - 非提的救赎 Fzu-2190 (单调栈)
- FZU 2190 非提的救赎(单调栈)
- Fzu-2190 非提的救赎 (单调栈)
- FZU2190(单调栈)
- [杂题]FZU2190 非提的救赎
- 【单调栈】fzu 2136取糖果
- FZU 2163 多米诺骨牌(单调栈)
- FZU 1845 Look Up(单调栈)
- fzoj Problem 2190 非提的救赎 【单调栈】
- Fzu 2058 Another a+b【离散化+思维】
- FZU 2141
- Educational Codeforces Round 23 D. Imbalanced Array(单调栈或RMQ+二分)
- FZU 1046 Tempter of the Bone
- FZU 2254 英语考试 (最小生成树)(福州大学第十四届程序设计竞赛)
- HDU 5726--GCD【倍增】【单调栈】【STL-map】
- POJ Feel Good (单调栈)
- FZU 2271 X (Floyd)(第七届福建省大学生程序设计竞赛)
- 单调栈
- fzu--据说题目很水