zoukankan      html  css  js  c++  java
  • 【动态规划】Vijos P1121 马拦过河卒

    题目链接:

      https://vijos.org/p/1616

    题目大意:

      卒从(0,0)走到(n,m),只能向下或向右,不能被马一步碰到或走到马,有几种走法。

    题目思路:

      【动态规划】

      把马控制的地方全部标记,接下来DP,f[i][j]=f[i-1][j]+f[i][j-1];

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<memory.h>
    10 #include<time.h>
    11 #include<stdio.h>
    12 #include<stdlib.h>
    13 #include<string.h>
    14 //#include<stdbool.h>
    15 #include<math.h>
    16 #define min(a,b) ((a)<(b)?(a):(b))
    17 #define max(a,b) ((a)>(b)?(a):(b))
    18 #define abs(a) ((a)>0?(a):(-(a)))
    19 #define lowbit(a) (a&(-a))
    20 #define sqr(a) ((a)*(a))
    21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    22 #define mem(a,b) memset(a,b,sizeof(a))
    23 #define eps (1e-8)
    24 #define J 10
    25 #define MAX 0x7f7f7f7f
    26 #define PI 3.14159265358979323
    27 #define N 24
    28 using namespace std;
    29 typedef long long LL;
    30 int cas,cass;
    31 int n,m,lll,ans;
    32 int f[N][N];
    33 int main()
    34 {
    35     #ifndef ONLINE_JUDGE
    36 //    freopen("1.txt","r",stdin);
    37 //    freopen("2.txt","w",stdout);
    38     #endif
    39     int i,j,hx,hy;
    40 //    for(scanf("%d",&cas);cas;cas--)
    41 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    42     while(~scanf("%d",&n))
    43 //    while(~scanf("%d",&n))
    44     {
    45         scanf("%d%d%d",&m,&hx,&hy);
    46         n+=2,m+=2,hx+=2,hy+=2;
    47         f[hx][hy]=f[hx-2][hy-1]=f[hx-2][hy+1]=f[hx-1][hy-2]=f[hx-1][hy+2]=f[hx+1][hy-2]=f[hx+1][hy+2]=f[hx+2][hy-1]=f[hx+2][hy+1]=-MAX;
    48         f[2][1]=1,f[1][2]=0;
    49         for(i=2;i<=n;i++)
    50         {
    51             for(j=2;j<=m;j++)
    52             {
    53                 if(f[i][j]==-MAX)continue;
    54                 if(f[i-1][j]!=-MAX)f[i][j]+=f[i-1][j];
    55                 if(f[i][j-1]!=-MAX)f[i][j]+=f[i][j-1];
    56             }
    57         }
    58         printf("%d
    ",f[n][m]);
    59     }
    60     return 0;
    61 }
    62 /*
    63 //
    64 
    65 //
    66 */
    View Code
  • 相关阅读:
    第二次刷题感受——路漫漫其修远兮,吾将上下而求索。
    刷题就是照镜子——第一次刷2008年初赛题感受
    第一次集训刷题感受
    我的第一个博客
    预测房价的回归问题
    电影评论的情感极性分析
    语音助手是这样子的(二)
    语音助手是这样子的(一)
    软工第一次作业
    2020软件工程第五次作业_第二组
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5777619.html
Copyright © 2011-2022 走看看