codeforces 611C New Year and Domino (DP)
来源:互联网 发布:知乎付费方式 编辑:程序博客网 时间:2024/06/15 15:33
以地图左上角作为矩形左上角
用dp[i][j]表示以这个点作为右下角的矩形能摆放的所有骨牌,dp[i][j][0]是横着放,dp[i][j][1]是竖着放的,求出每个点的值后,能直接计算出答案,画图就能懂。
#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<cstdlib>#include<cctype>using namespace std;char pic[510][510];int dp[510][510][2];int main(){// freopen("D://input.txt","r",stdin); int n,m; scanf("%d%d",&n,&m); int i,j; for(i=1;i<=n;i++) scanf("%s",pic[i]+1); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ dp[i][j][0]=dp[i][j-1][0]+dp[i-1][j][0]-dp[i-1][j-1][0]; if(pic[i][j]=='.'&&pic[i][j-1]=='.')dp[i][j][0]++; dp[i][j][1]=dp[i-1][j][1]+dp[i][j-1][1]-dp[i-1][j-1][1]; if(pic[i][j]=='.'&&pic[i-1][j]=='.')dp[i][j][1]++; } } int q; scanf("%d",&q); while(q--){ int x[2],y[2]; scanf("%d%d%d%d",&x[0],&y[0],&x[1],&y[1]); printf("%d\n",dp[x[1]][y[1]][0]-dp[x[1]][y[0]][0]-dp[x[0]-1][y[1]][0]+dp[x[0]-1][y[0]][0] +dp[x[1]][y[1]][1]-dp[x[1]][y[0]-1][1]-dp[x[0]][y[1]][1]+dp[x[0]][y[0]-1][1]); } return 0;}
0 0
- Codeforces 611C New Year and Domino(dp)
- codeforces 611C New Year and Domino (DP)
- Codeforces 611C New Year and Domino DP+前缀和
- codeforces-611C-New Year and Domino
- CodeForces 611C New Year and Domino
- codeforces 611C New Year and Domino DP预处理+部分和思想
- CodeForces 611 C. New Year and Domino(dp+容斥)
- Codeforces 611C:New Year and Domino 二维前缀和
- Codeforces 611C:New Year and Domino 二维前缀和
- CodeForces 611C New Year and Domino【预处理】
- 【Goodbye2015】Codeforces 611C New Year and Domino【思维】
- CodeForces 611CNew Year and Domino(DP)
- C. New Year and Domino
- Codeforces Good Bye 2015 C. New Year and Domino (预处理)
- codeforces Good Bye 2015 C - New Year and Domino
- Good Bye 2015 C New Year and Domino(dp)
- cf#gb2015-C. New Year and Domino-dp
- Codeforces 611C. New Year and Domino (Good Bye 2015 C题)
- 【总结】C#中的数组
- Leetcode214: Remove Invalid Parentheses
- iOS: 在UIViewController 中添加Static UITableView
- git的学习和使用
- 更改eclipse的编辑器样式风格
- codeforces 611C New Year and Domino (DP)
- UILabel+UIImageView(动画)
- 围观M$的new
- 【HDU4001】To Miss Our Children Time(LIS变形)
- 关于国外硕博士论文搜索和下载的讨论
- java一点浅薄的东西 分享2
- Android自带刷新控件SwipeRefreshLayout扩展,支持ListView下拉刷新
- LAMP---文章发布系统
- 解决android.view.InflateException: Binary XML file line #8: Error inflating class