日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codevs1219 骑士遍历(棋盘DP)

發布時間:2023/12/13 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codevs1219 骑士遍历(棋盘DP) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述?Description

設有一個n*m的棋盤(2≤n≤50,2m≤50),如下圖,在棋盤上有一個中國象棋馬。

規定:

1)馬只能走日字

2)馬只能向右跳

問給定起點x1,y1和終點x2,y2,求出馬從x1,y1出發到x2,y2的合法路徑條數。

輸入描述?Input Description

第一行2個整數n和m

第二行4個整數x1,y1,x2,y2

輸出描述?Output Description

輸出方案數

樣例輸入?Sample Input

30 30

1 15 3 15

樣例輸出?Sample Output

2

數據范圍及提示?Data Size & Hint

2<=n,m<=50


水題,直接推就行了。。。


#include<iostream> #include<cassert> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<string> #include<iterator> #include<cstdlib> #include<vector> #include<stack> #include<map> #include<set> using namespace std; #define rep(i,f,t) for(int i = (f),_end_=(t); i <= _end_; ++i) #define rep2(i,f,t) for(int i = (f),_end_=(t); i < _end_; ++i) #define dep(i,f,t) for(int i = (f),_end_=(t); i >= _end_; --i) #define dep2(i,f,t) for(int i = (f),_end_=(t); i > _end_; --i) #define clr(c, x) memset(c, x, sizeof(c) ) typedef long long int64; const int INF = 0x5f5f5f5f; const double eps = 1e-8;//*****************************************************int64 d[55][55];int main() {int n,m,x1,x2,y1,y2;scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2);if(x2 <= x1){cout<<0<<endl;return 0;}clr(d,0);d[x1][y1] = 1;for(int i = x1; i < x2; ++i){for(int j = 1; j <= m; ++j){if(d[i][j]){d[i+1][j+2] += d[i][j];d[i+2][j+1] += d[i][j];if(j-2 > 0) d[i+1][j-2] += d[i][j];if(j-1 > 0) d[i+2][j-1] += d[i][j];}}}cout<<d[x2][y2]<<endl;return 0; }




版權聲明:本文為博主原創文章,未經博主允許不得轉載。

轉載于:https://www.cnblogs.com/DSChan/p/4862020.html

總結

以上是生活随笔為你收集整理的codevs1219 骑士遍历(棋盘DP)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。