首页 > 其他分享 >7/22上午

7/22上午

时间:2023-07-22 11:12:14浏览次数:39  
标签:false cn 22 int nx ny 上午 1005


1212LETTERS

http://ybt.ssoier.cn:8088/problem_show.php?pid=1212

#include<bits/stdc++.h>
using namespace std;

int maxs=0;
bool a[25][25],b[10005];
char c[25][25];
int R,S;
int x[4]={1,0,-1,0};
int y[4]={0,1,0,-1};

void dfs(int m,int n,int s){
    if(s>maxs){
        maxs=s;
    }
    for(int i=0; i<=3; i++){ 
        int nx=x[i]+m;
        int ny=y[i]+n;
        if(nx<=R && ny<=S && nx>=1 && ny>=1){
            if(b[c[nx][ny]]==false && a[nx][ny]==false){
                b[c[nx][ny]]=true;
                a[nx][ny]=true; 
                dfs(nx,ny,s+1);
                b[c[nx][ny]]=false;
                a[nx][ny]=false;
               }
            
        }
    }
}

int main(){
    cin>>R>>S;
    for(int i=1; i<=R; i++){
        for(int j=1; j<=S; j++){
            cin>>c[i][j];
        }
    }
    b[c[1][1]]=1;
    dfs(1,1,1);
    cout<<maxs<<endl;
    return 0;
}

 

1258数字金字塔

 http://ybt.ssoier.cn:8088/problem_show.php?pid=1258

递归+记忆化(满分法):

#include<bits/stdc++.h>
using namespace std;

int R;
int a[1005][1005];
int s[1005][1005];

int f(int m,int n){
    if(m==R){
        return a[m][n];
    }else {
        if(s[m][n]==0){
            s[m][n]=max(f(m+1,n),f(m+1,n+1));
        }
        return a[m][n]+s[m][n];
    }
}

int main(){
    cin>>R;
    for(int i=1; i<=R; i++){
        for(int j=1; j<=i; j++){
            cin>>a[i][j];
        }
    }
    cout<<f(1,1)<<endl; 
    return 0;
}

 1215 迷宫 

http://ybt.ssoier.cn:8088/problem_show.php?pid=1215

#include<bits/stdc++.h>
using namespace std;

int k,h;
char c[105][105];
bool ans=false;
int x[4]={1,0,-1,0};
int y[4]={0,-1,0,1};
int ax,ay,bx,by,nx,ny;
bool b[1005][1005];

void dfp(int x1,int y1){
    if(ans){
        return ;
    }
    
    for(int i=0; i<=3; i++){
        nx=x[i]+x1;
        ny=y[i]+y1;
        if(c[nx][ny]=='.' && nx>=0 && nx<h && ny>=0 && ny<h && b[nx][ny]==false){
            if(nx==bx && ny==by){
                ans=true;
            }
            b[nx][ny]=true;
            dfp(nx,ny);
            b[nx][ny]=false;
        }
    }
}
 
int main(){
    cin>>k;
    for(int i=0; i<k; i++){
        cin>>h;
        for(int j=0; j<h; j++){
            for(int z=0; z<h; z++){
                cin>>c[j][z];
            }
        }
        cin>>ax>>ay>>bx>>by;
        dfp(ax,ay);
        if(ans==false){
            cout<<"NO"<<endl;
        }else cout<<"YES"<<endl;
        ans=false;
        memset(b,0,sizeof(b));//要记得清空!!! 
    }
    return 0;
}

 

1213八皇后问题 (未完成)

http://ybt.ssoier.cn:8088/problem_show.php?pid=1213

 

#include<bits/stdc++.h>
using namespace std;

int a[10][10],s=0;
bool b[1000], c[1000],d[1000],e[1000];

void output(){
    cout<<"NO. "<<s<<endl;
    for(int i=1; i<=8; i++){
        for(int j=1; j<=8; j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}

void dfs(int m){
    for(int j=1; j<=8; j++){
        if(b[j]==false && c[m+j]==false && d[m-j+7]==false){
            a[m][j]=1;
            b[j]=true;
            c[m+j]=true;
            d[m-j+7]=true;
            if(m==8){
                    s++;
                    output();
                    memset(a,0,sizeof(a));
            }else {
                dfs(m+1);
            }
            b[j]=false;
            c[m+j]=false;
            d[m-j+7]=false;
        }
    }
}



int main(){
    dfs(1); 
    return 0;
}

 

标签:false,cn,22,int,nx,ny,上午,1005
From: https://www.cnblogs.com/dxy09tj/p/17572846.html

相关文章

  • 7/22·morning
    1269:【例9.13】庆功会  http://ybt.ssoier.cn:8088/problem_show.php?pid=1269#include<bits/stdc++.h>usingnamespacestd;intn,m;intw[503],v[503],s[503];intdp[6007];intmain(){cin>>n>>m;for(inti=1;i<=n;i++){cin>&......
  • leetcode 栈与队列 232 225
    目录基本介绍四个问题232225基本介绍栈,先进后出队列,先进先出四个问题C++中stack是容器么?我们使用的stack是属于哪个版本的STL?我们使用的STL中stack是如何实现的?stack提供迭代器来遍历stack空间么?首先大家要知道栈和队列是STL(C++标准库)里面的两个数据结构。C++标准......
  • ssh连接设置更改数据库名不起效果,连接127.0.0.1更换127.0.0.22也不报错
    ssh连接设置更改数据库名不起效果,连接127.0.0.1更换127.0.0.22也不报错 浏览器缓存清除后也一样。更换浏览器一样tomcat重启无效work目录全部删除无效myeclipse重新build工程无效重启myeclipse无效tomcat程序不指向工程下的webroot改为发布到webapp无效更换端口为8081的tomcat6无......
  • USG6395恢复登录密码和FC交换机2224console登录用户及密码
    一、USG6395恢复登录密码 CTRL+B以后需要输入的密码是Admin@huawei,password恢复出厂以后,reboot,进入console界面可以修改admin的密码,再次重启以后就可以正常网页登录了。二、FC交换机2224console的默认用户是root密码为Huawei12#$......
  • 【网络流,dp】Gym102220A Apple Business
    ProblemLink有一棵\(n\)个点的完全二叉树(点\(i\)的父亲是\(\lfloori/2\rfloor\)),第\(i\)个点有\(a_i\)个苹果。现在有\(m\)个订单,每个订单只接受\(u_i\)到\(v_i\)路径上的苹果,保证\(u_i\)是\(v_i\)的父亲,并且最多只接受\(c_i\)个苹果,单价为\(w_i\)。你可......
  • 7.20上午-分模-进胶
      ......
  • DL100 PN替换 DL100 RS422调试实例
    第一部分:现场问题描述 客户使用DL100的422通讯,需要西门子PLC使用过多422模块,PLC接入模块数量有限。换成DL100的PN通讯,使用交换机来处理。同时之前的使用中,遇到了DL100烧坏的问题。 第二部分:现场工作内容 1. 产品自身功能和参数设置体现: 接线:422通讯的接......
  • Visual Studio IDE 2022 - how to disable navigation to decompiled sources
    VisualStudioIDE2022-howtodisablenavigationtodecompiledsources ......
  • 斯坦福 CS229 机器学习中文讲义 翻译完成
    斯坦福CS229机器学习中文讲义第一部分到第三部分第四部分生成学习算法第五部分支持向量机第六部分学习理论第七部分正则化与模型选择感知器和大型边界分类器K均值聚类算法混合高斯和期望最大化算法第九部分期望最大化算法第十部分因子分析第十一部分主成分分析第十二部分......
  • [LeetCode] 2268. Minimum Number of Keypresses
    Youhaveakeypadwith 9 buttons,numberedfrom 1 to 9,eachmappedtolowercaseEnglishletters.Youcanchoosewhichcharacterseachbuttonismatchedtoaslongas:All26lowercaseEnglishlettersaremappedto.Eachcharacterismappedtoby exact......