站外题求助
  • 板块灌水区
  • 楼主__KevinMZ__
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/24 20:30
  • 上次更新2024/11/24 21:46:58
查看原帖
站外题求助
1358215
__KevinMZ__楼主2024/11/24 20:30

#include<bits/stdc++.h>
using namespace std;
int a[20][20],n,m,cnt;
set<int>st;
int b[1145];
bool in(int x,int y){
    return *st.lower_bound(a[x][y])==a[x][y]&&st.lower_bound(a[x][y])!=st.end() ;
}
void bl(){
    for(auto i:st)cout<<i<<" ";cout<<"\n";
}
void dfs(int x,int y,int z){
    b[z]=a[x][y];
    if(x==n&&y==m){
        cnt++;
        return;
    }
    st.insert(a[x][y]);
    if(in(x+1,y)&&in(y+1,x))return;
    if(!in(x+1,y))dfs(x+1,y,z+1);
    if(!in(x,y+1))dfs(x,y+1,z+1);
    st.erase(a[x][y]);
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
    dfs(1,1,1);
    cout<<cnt;
    return 0;
}

2024/11/24 20:30
加载中...