poj1315 Don't Get Rooked

数值计算之 插值法(4)切比雪夫零点插值 数值计算之 插值法(4)切比雪夫零点插值前言插值点选取第一类切比雪夫多项式拉格朗日插值多项式的余项切比雪夫零点插值后记 前言 上篇插值法讨论了多项式插值的解,以及龙格现象。本篇将介绍一种在抽取节点时有效降低龙格现象的方法——切比雪夫零点插值。 插值点选取 插值多项式阶数较高时,在取值空间均匀取点,容易出现龙格现象。 即区间边缘的插值结果与原函数差异很大,而区间中央的插值结果相对较好。这表明,高阶多项式插值对区间中央的节点拟合好,而对两端节点拟合效果差。 自然而然会想到,在两端多采样一些节点,在中间少采样一 阅读详情

Don't Get Rooked
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 2134 Accepted: 1359

Description

In chess, the rook is a piece that can move any number of squares vertically or horizontally. In this problem we will consider small chess boards (at most 4x4) that can also contain walls through which rooks cannot move. The goal is to place as many rooks on a board as possible so that no two can capture each other. A configuration of rooks is legal provided that no two rooks are on the same horizontal row or vertical column unless there is at least one wall separating them. 

The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of rooks in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways. 

Your task is to write a program that, given a description of a board, calculates the maximum number of rooks that can be placed on the board in a legal configuration. 

Input

The input contains one or more board descriptions, followed by a line containing the number 0 that signals the end of the file. Each board description begins with a line containing a positive integer n that is the size of the board; n will be at most 4. The next n lines each describe one row of the board, with a '.' indicating an open space and an uppercase 'X' indicating a wall. There are no spaces in the input.

Output

For each test case, output one line containing the maximum number of rooks that can be placed on the board in a legal configuration.

Sample Input

4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0

Sample Output

5
1
5
2
4

Source



总情况数也就2^(4*4)大概6W多种,暴力dfs一下就行了

如果再大点要么网络流(?)要么状态dp吧……

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int n,cnt;
char map[5][5];
int put[20];
struct Point
{
    int x,y;
};

bool Check(int p,int q)
{
    Point s,t;
    int i;
    s.x=p/n;s.y=p%n;
    t.x=q/n;t.y=q%n;
    bool row,col;
    if (s.x!=t.x) row=false;
    else
    {
        for (i=min(s.y,t.y)+1;i<max(s.y,t.y);i++)
        {
            if (map[s.x][i]=='X') break;
        }
        if (i==max(s.y,t.y)) row=true;
        else row=false;
    }
    if (s.y!=t.y) col=false;
    else
    {
        for (i=min(s.x,t.x)+1;i<max(s.x,t.x);i++)
        {
            if (map[i][s.y]=='X') break;
        }
        if (i==max(s.x,t.x)) col=true;
        else col=false;
    }
    return (col | row);
}


void DFS(int t,int now)
{
    int i;
    if (t==n*n)
    {
        cnt=max(cnt,now);
        return;
    }
    DFS(t+1,now);
    if (map[t/n][t%n]=='X') return;
    for (i=0;i<now;i++)
    {
        if (Check(put[i],t)) break;
    }
    if (i<now) return;
    put[now]=t;
    DFS(t+1,now+1);
}

int main()
{
    int i,j;
    while(1)
    {
        scanf("%d",&n);
        if (n==0) break;
        for (i=0;i<n;i++)
        {
            scanf("%s",map[i]);
        }
        cnt=0;
        DFS(0,0);
        printf("%d\n",cnt);
    }
    return 0;
}


LangChain4j-针对性操作Function-call+系统预设角色 如果我们想要对一些敏感信息进行针对化的操作,不仅仅是接口大模型去进行回复。比如我们现在数据库里面有一些菜品,那么用户提问,店里有多少套餐,那么云端大模型肯定是不知道的,我们希望捕获这些关键字然后进行自己的业务查询或者处理,这个时候就可以使用function-call。 阅读详情

相关推荐

SAP打印错位问题终极解决指南:LP01设备格式设置全流程

本文详细解析了SAP系统中LP01设备打印错位问题的解决方案,重点介绍了SPAD事务码的配置流程和格式设置技巧。通过精准调整输出设备、设备类型和格式类型的匹配关系,有效解决'未定义格式'错误,确保打印内容准确对齐。文章还提供了高级排查方法和预防措施,帮助SAP管理员提升打印管理效率。

weixin_29311017的博客 397

poj 1315 dfs(带障碍的类八皇后)

简单dfs #include #include #define max(a,b) ((a)>(b)?(a):(b)) #define N 5 char s[N][N]; int flag[N][N],n,res,now; void dfs(int d,int s[N][N],int ava){ int x = d/n; int y = d%n; int i,j,t[N][N]; fo

dearmango 920

【分享】ArcGIS实现分子分母等标注实用技巧

前言 标注是显示在地图上的文字信息,是出图中不可或缺的重要元素,为了标注的样式丰富,摆放的位置灵活,因此给制图出图带来不少难度,以下分享几种本人在ArcGIS中的标注方法,实现上下标注、换行标注或分式标注的实用技巧。 普通模式与高级模式 默认为普通模式,勾选高级开启高级模式。 普通二分式标注(普通模式) [DLBM] & vbnewline & [DLMC] 标注效果展示 分行二分式标注(普通模式) [DLBM]& vbnewline & "——————" &

杨港 3万+

POJ1315【Don‘t Get Rooked】(递归与回溯、dfs)

链接:POJ1315【Don’t Get Rooked】 题目描述: In chess, the rook is a piece that can move any number of squares vertically or horizontally. In this problem we will consider small chess boards (at most 4x4) that can also contain walls through which rooks cannot move.

Obliviate的博客 246

软件安装管家matlab教程,timesat软件怎么安装 timesat安装使用图文教程 - 驱动管家...

TimeSat是一款不错的时间序列滤波软件,很专业,在提取植被物候参数方面有着很好的应用,本文主要讲解TimeSat 3.1软件在Windows和Matlab平台的安装及TimeSat 3.1软件的使用和说明详解。一、TimeSat 3.1软件安装;本文讲解TimeSat 3.1软件在Windows和Matlab平台的安装。1、打开Matlab 2011,点击菜单中的File→Set Path,如...

weixin_42112894的博客 1980

5步搞定ABB机器人RobotStudio与S7-1500PLC的Profinet通讯(附PLCSIM调试技巧)

本文详细介绍了如何利用RobotStudio与TIA Portal软件,结合PLCSIM Advanced仿真器,在零硬件条件下实现ABB机器人与西门子S7-1500 PLC之间的Profinet通讯虚拟调试。通过五个核心步骤,从环境搭建、网络配置、信号映射到联合仿真与高级调试,帮助工程师在项目前期高效验证逻辑、压缩现场调试周期,并掌握实用的PLCSIM调试技巧。

weixin_29188043的博客 529

poj 1315 Don‘t Get Rooked

题目链接Don’t Get Rooked 题意: 给一个最多4 × 4的棋盘,每放置一个点,与这个点同行同列就不能再放点 除非两个点在墙的两侧,问给定规模的棋盘最多能放多少个点 思路: 数据少,直接暴力dfs #include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; char chess[5][5]; bool vis[5]

CUCUC1的博客 261

【LSTM回归预测】attention机制LSTM时间序列回归预测【含Matlab源码 1992期】

attention机制LSTM时间序列回归预测 完整的代码,方可运行;可提供运行操作视频!适合小白!

订阅付费专栏Matlab(奶茶价版),可赠送奶茶价版付费专栏指定代码1份; 2600

poj 1315 Don't Get Rooked

dfs

GadyPu的专栏 500

对CryptoDriver里密钥格式定义的探索(1)

一入网络安全才发现深似海,传统汽车MCU码农转型之路异常艰难。在CP AUTOSAR中的CryptoDriver SWS对密钥格式的需求来源于RFC,其中要求了RSA、ECC、SHE等key material的格式。再往下看,我就有些迷糊了,例如关于RSA Private Key的OCTEE STRING格式根据IETF RFC8017,Public Key又得根据RFC5280,完全不得其解。所以今天先从生成密钥对,并对其进行解析开始,一步一步拆解。

认真搞搞汽车MCU 540

手把手教你学Simulink——高频隔离型双向DC-AC逆变器的建模与仿真

本文系统讲解高频隔离型双向DC-AC逆变器的Simulink建模与仿真,基于DAB+全桥逆变两级拓扑,详述DAB移相控制原理、双闭环控制策略及分步仿真搭建流程。重点涵盖电路建模、控制环设计、参数设置与常见问题调试,强调模块化分步验证与分层控制逻辑,实现安全、高效、灵活的双向能量流动仿真,适用于储能、微电网等场景的系统开发与验证。

MHD0815的博客 123

POJ1315:Don't Get Rooked

点击打开题目链接 Language: Default Don't Get Rooked Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2078   Accepted: 1317 Description In chess, the ro

I just want to AC you~~~ 1609

基于YOLOv8的农作物病虫害检测系统设计与实现

国内如中国农业大学的科研团队采用改进的Faster R-CNN模型对小麦病害进行检测,取得了较好的效果。农作物病虫害是影响农业生产的重要因素之一,每年因病虫害导致的农作物减产高达20%-40%。YOLO(You Only Look Once)系列算法作为目标检测领域的代表性模型,以其高效、准确的特点在众多领域得到广泛应用。YOLOv8作为该系列的最新版本,在精度和速度上都有显著提升,非常适合农作物病虫害检测这类需要实时处理的应用场景。然而,现有研究仍存在一些不足:一是模型复杂度高,难以部署到移动设备;

YOLO 799

POJ1315 Don't Get Rooked【DFS】

纯dfs #include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;iomanip&gt; #include &lt;string&gt; #include &lt;cstring&gt; #include &lt;cmath&gt; #include &lt;algorithm&gt; #include &lt;queu

lhc----- 359

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Don't Get Rooked(poj1315,dfs)

http://poj.org/problem?id=1315 Don't Get Rooked Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2082 Accepted: 1321 Description In chess, the rook is a piece that can move any number

JHC23的专栏 982

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

poj 1315 Don't Get Rooked 暴力枚举

//poj 1315 //sep9 #include using namespace std; int n; char g[8][8]; int tmp[8][8]; bool check() { for(int i=0;i<n;++i){ int flag=0; for(int j=0;j<n;++j){ if(g[i][j]=='X'&&tmp[i][j]==0){

sepNINE的专栏 698

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

POJ1315 UVA639 UVALive5325 Don't Get Rooked【DFS】

Don’t Get Rooked Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2631 Accepted: 1682 Description In chess, the rook is a piece that can move any number of squares vertically or horizontal...

海岛Blog 595

UVa 639 & HOJ 1086 & POJ 1315 - Don't Get Rooked

传送门UVa 639 & HOJ 1086 & POJ 1315 - Don't Get Rooked 刚开始想用超级暴力法做,

一只冰熊 1274

POJ 1315 Don't Get Rooked(DFS)

和N皇后问题类似,这道题让求出棋盘在被墙分隔的情况下的最多能放的棋子的个数,使分隔后的每行每列仅有一个棋子。方法是从前到后dfs,同时用4个循环判断位置是否合法。

Noooooorth的专栏 1742

POJ 1315 Don't Get Rooked

Don't Get Rooked Time Limit:1000MS Memory Limit:10000K Total Submissions:2086 Accepted:1325 Description In chess, the rook is a piece that can move any number of sq...

weixin_30273763的博客 107

POJ 1315 Don't Get Rooked(dfs)

A -Don't Get Rooked Time Limit:1000MSMemory Limit:10000KB64bit IO Format:%I64d & %I64u SubmitStatusPracticePOJ 1315 Description In chess, the rook is a piece that can m...

weixin_30852367的博客 99

POJ1315 UVA639 UVALive5325 Don't Get Rooked题解

代码来源:DeathYmz AC的C++语言程序如下: #include #include #include #include using namespace std; const int N=10; int n,ans; char board[N][N]; int vis[N][N]; void f(int i,int j,int v) { vis[i][j]+=v; for(i

海岛Blog 715

POJ-1315 Don‘t Get Rooked C++题解

【代码】POJ-1315 Don't Get Rooked C++题解。

Enjoy10ve的博客 235

poj1315 Don\'t Get Rooked

这是第一个DFS题,没有任何头绪,所以参考别人的程序http://www.cnblogs.com/lzmfywz/p/3240249.htmlimport java.util.Scanner;public class NoRooked { static char str[][]; static int map[][]; static int ans; static int n;

萝卜@兔子的专栏 415

POJ 1315 Dont Get Rooked G++ dfs 巧妙 背

n*n的棋盘,字符X表示墙,棋子不能同行也不能同列,求最大能放多少棋子。

woniupengpeng的专栏 604

poj1315 Don‘t Get Rooked (dfs加回溯)

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char da[108][108]; int hs[108][108]; int ans;//全局变量记录放车数量的最大值。 int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; int n; void update(int ..

baymax先生的博客 151
上一篇: poj1329 Circle Through Three Points
下一篇: poj2893 M × N Puzzle
magicnumber
博客等级 码龄18年 119粉丝 196原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址