[2016 indeed笔试题] Tables and Pieces
来源:互联网 发布:淘宝卖家代销怎么发货 编辑:程序博客网 时间:2024/06/07 18:05
Question
There is a 6×6 table. Place a number of pieces on the table to meet the following conditions:
There is to be either zero or one piece in each square of the table.
Each column in the table is to have exactly three pieces.
Each row in the table is to have exactly three pieces.
There may already be pieces in some of the squares of the table. When si,j is 'o', there is already a piece in the square at the jth column of the ith row. When that is not the case, si,j is '.' and there is no piece in that square. Find out the number of ways to place pieces in the empty squares, which satisfies the conditions. Two ways are considered different if they have at least one square which contains a piece in one way and doesn't contain a piece in the other way.
Constrains
si,j is 'o' or '.'
Input
Inputs are provided from standard inputs in the following form.
s1,1 … s1,6
:
s6,1 … s6,6
Output
Output the number of ways that pieces can be placed on the empty squares to satisfy the conditions.
Input Example #1
......
.o....
...o..
...o..
......
......
Output Example #1
32692
Input Example #2
oooo..
......
......
......
......
......
Output Example #2
0
There is a 6×6 table. Place a number of pieces on the table to meet the following conditions:
There is to be either zero or one piece in each square of the table.
Each column in the table is to have exactly three pieces.
Each row in the table is to have exactly three pieces.
There may already be pieces in some of the squares of the table. When si,j is 'o', there is already a piece in the square at the jth column of the ith row. When that is not the case, si,j is '.' and there is no piece in that square. Find out the number of ways to place pieces in the empty squares, which satisfies the conditions. Two ways are considered different if they have at least one square which contains a piece in one way and doesn't contain a piece in the other way.
Constrains
si,j is 'o' or '.'
Input
Inputs are provided from standard inputs in the following form.
s1,1 … s1,6
:
s6,1 … s6,6
Output
Output the number of ways that pieces can be placed on the empty squares to satisfy the conditions.
Input Example #1
......
.o....
...o..
...o..
......
......
Output Example #1
32692
Input Example #2
oooo..
......
......
......
......
......
Output Example #2
0
题解:深搜枚举,2^36.大数据会超时
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;char s[7][7];int rowNum[7],colNum[7],res;void dfs(int r,int c) { if(c>=6) { if(rowNum[r]!=3) {return;} dfs(r+1,0); } if(r==6) { for(int i=0;i<6;i++) { if(colNum[i]!=3) {return;} } res++; return; }if(6-(c+1)+rowNum[r]>=3) dfs(r,c+1); if(s[r][c]=='.'&&(colNum[c]+1)<=3) { rowNum[r]++; colNum[c]++; if(rowNum[r]==3) { dfs(r+1,0); } else dfs(r,c+1);rowNum[r]--; colNum[c]--; }}int main(){ bool flag=true;memset(rowNum,0,sizeof(rowNum));memset(colNum,0,sizeof(colNum)); for(int i=0;i<6;i++) { for(int j=0;j<6;j++) { scanf("%c",&s[i][j]);if(s[i][j]=='o') {rowNum[i]++; colNum[j]++;}if(colNum[j]>3) {flag=false;} } if(rowNum[i]>3) {flag=false;} getchar(); } res=0; if(!flag) {printf("0\n"); return 0; } dfs(0,0); printf("%d\n",res); return 0;}
0 0
- [2016 indeed笔试题] Tables and Pieces
- indeed 在线笔试题
- indeed一道在线笔试题
- 2017 Indeed-tokyo笔试题-6*6的矩阵放置元素
- indeed秋招笔试第一场
- Bits and Pieces 模拟
- uva12296 Pieces and Discs
- 【在线笔试题解题报告系列】Indeed Tokyo 2017校园招聘 在线测试3(时间:2016.07.09)
- SQL Exercises/Pieces and providers
- Erlang and Cloud Computing: A Fine Pair Indeed
- Pieces
- POJ3014 Cake Pieces and Plates DP
- POJ 3014 Cake Pieces and Plates 可能会
- Pooled and Cluster Tables
- Create Tables and Constraints
- Pooled and Cluster Tables
- watir and ajax tables
- Tables, Matrices, and Lists
- 计蒜之道复赛A题 百度地图的实时路况(分治+floyd)
- ssh初步整合
- TCP/IP协议栈与数据包封装
- day——05 迭代器,生成器
- Redis need tcl 8.5 or newer
- [2016 indeed笔试题] Tables and Pieces
- 求一个圆的面积及判断一个点是否在圆内
- redis数据类型
- char * 和 char[]
- windows下的mysql主从复制
- Tomcat源码分析之ClassLoader部分的设计详细分析
- 继承中的访问顺序
- 两种加载数据库方式
- Android四大组件之Service初涉