codeforces 253D 单调队列 好题
2012-12-12 16:49
344 查看
View Code
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char map[404][404]; int a[404][404]; int n, m, k, sum; __int64 ans; int cnt[33]; int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int i, j, l, r; scanf("%d%d%d", &n, &m, &k); for(i = 1; i <= n; i++) { scanf("%s", map[i]+1); for(j = 1; j <= m; j++) a[i][j] = (map[i][j] == 'a') + a[i-1][j]; } for(i = 1; i < n; i++) for(j = i+1; j <= n; j++) { memset(cnt, 0, sizeof(cnt)); sum = 0; l = 1; for(r = 1; r <= m; r++) { sum += a[j][r] - a[i-1][r]; if(map[i][r] == map[j][r]) cnt[map[i][r]-'a']++; while( sum > k && l <= r) // deque { sum -= a[j][l] - a[i-1][l]; if(map[i][l] == map[j][l]) cnt[map[i][l]-'a']--; l++; } if(l < r && map[i][r] == map[j][r]) // pay attention "l < r", the lenth must > 1 in this problem. ans += cnt[map[i][r]-'a']-1; } } printf("%I64d\n", ans); return 0; }
相关文章推荐
- codeforces 253D 单调队列 好题
- CodeForces - 91B 单调队列 或 线段树
- CodeForces 602D 【单调队列】【简单数学】
- CodeForces 15D Map 单调队列优化
- codeforces 940E(单调队列+dp)
- Codeforces 15D Map 单调队列+构造
- codeforces 251A Points on Line 二分 or 单调队列
- CodeForces 939F Cutlet(dp+单调队列优化)
- DP训练 codeforces 372C Watching Fireworks is Fun [单调队列优化dp]
- codeforces 372C Watching Fireworks is Fun 单调队列优化dp
- CodeForces 601B Lipshitz Sequence (单调队列)
- Codeforces 939F.Cutlet-单调队列优化dp
- CodeForces - 91B单调队列
- Codeforces 797F Mice And Holes DP(单调队列优化)
- Codeforces 373E Watching Fireworks is Fun【思维+单调队列优化Dp+滚动数组】
- CodeForces 319B-Psychos in a Line(单调队列)
- codeforces 251A(普通队列or单调队列or二分)
- codeforces 251A Points on Line(二分or单调队列)
- codeforces 939F 单调队列优化dp
- codeforces 251A Points on Line 二分 or 单调队列