FZU 2064(暴力求解)

来源:互联网 发布:mac怎么找到安装目录 编辑:程序博客网 时间:2024/05/17 00:10
找位置
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u


Description

一年一次的FZUACM宣讲会又开始 了,kk和几个同学到的时候位置已经不多了。但是他们又想坐在同一排而且位置要连在一起。现在给你宣讲会现场的情况请问有多少种座法满足条件,对于两种坐法如果有一个位置不同就算是两种不同的坐法。

Input

第一行一个整数T,表示有T组数据。

每组数据第一行三个正整数N M W(1<N,M,W<=100), 表示宣讲会现场是一个N*M 的座位和kk一伙来了W个人。其中N是排数,M是列数。

接着N行每行M个数(0或1),0表示空位,1表示有人坐了。

Output

对于每组数据,输出有多少种坐法。

Sample Input

22 3 30 0 11 0 02 5 30 1 0 1 00 0 0 0 0

Sample Output

03


解析:我刚刚开始把这题给想复杂了,用回溯来求解,其实这题没有这么复杂,直接用两次for在加上判断是否越界,就可以解决了。


#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;const int N = 200;int m,n,w;int grid[N][N];bool judge(int r,int c) {for(int i = 0; i < w; i++) {if(grid[r][c+i]) {return false;}}return true;}int main() {int t;scanf("%d",&t);while(t--) {memset(grid,0,sizeof(grid));scanf("%d%d%d",&n,&m,&w);for(int i = 0; i < n; i++) {for(int j = 0; j < m; j++) {scanf("%d",&grid[i][j]);}}int ans = 0;for(int i = 0; i < n; i++) {for(int j = 0; j < m; j++) {if( j + w <= m && judge(i,j)) {ans++;}}}printf("%d\n",ans);}return 0;}


0 0
原创粉丝点击