• AOJ 763.过河卒


    过河卒
    Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
    Total Submission: 23   Submission Accepted: 5
     
    Description
    在一个n*m的矩阵上,A点有一个过河卒,需要走到目标B点。卒行走的规则:只能向下或者向右。每一步能水平或者垂直移动一个点(纵横线的交叉点)的距离。计算从A 点能够到达B点的路径的条数。
    设行、列数为m和n, 2<=m,n<=20
    Input
    只有一行,包含4个整数,即B点坐标(x1,y1) 和 A点坐标(x2,y2),
    保证A,B在地图内。
    Output
    一个整数,为路径的条数,答案对1000000007取模
    Sample Input
    Original Transformed
    6  6  3  2
    Sample Output
    Original Transformed
    35
    Hint
    可能走不到

    递推(dp)或者组合数

    最后答案记得取模

    AC代码:GitHub

     1 /*
     2 By:OhYee
     3 Github:OhYee
     4 HomePage:http://www.oyohyee.com
     5 Email:oyohyee@oyohyee.com
     6 Blog:http://www.cnblogs.com/ohyee/
     7  
     8 かしこいかわいい?
     9 エリーチカ!
    10 要写出来Хорошо的代码哦~
    11 */
    12  
    13 #include <cstdio>
    14 #include <algorithm>
    15 #include <cstring>
    16 #include <cmath>
    17 #include <string>
    18 #include <iostream>
    19 #include <vector>
    20 #include <list>
    21 #include <queue>
    22 #include <stack>
    23 #include <map>
    24 using namespace std;
    25  
    26 //DEBUG MODE
    27 #define debug 0
    28  
    29 //循环
    30 #define REP(n) for(int o=0;o<n;o++)
    31  
    32 //初始化
    33 #define mst(a,n) memset(a,n,sizeof(a))
    34  
    35 int Map[25][25];
    36 const int MOD = 1000000007;
    37  
    38 bool Do() {
    39     int x1,y1,x2,y2;
    40     if(scanf("%d%d%d%d",&x1,&y1,&x2,&y2) == EOF)
    41         return false;
    42  
    43     mst(Map,0);
    44  
    45     Map[x2][y2] = 1;
    46     for(int i = x2;i <= x1;i++)
    47         for(int j = y2;j <= y1;j++)
    48             if(!(i == x2&&j == y2))
    49                 Map[i][j] = (Map[i][j - 1] + Map[i - 1][j]) % MOD;
    50     printf("%d
    ",Map[x1][y1]);
    51     return true;
    52 }
    53  
    54 int main() {
    55     while(Do());
    56     return 0;
    57 }
  • 相关阅读:
    NOJ 1116 哈罗哈的大披萨 【淡蓝】 状态压缩DP
    优先队列原理与实现【转】
    testC-I
    济南NOIP冬令营 选拔(select)
    P4747 D’s problem(d)
    P4746 C’s problem(c)
    P4745 B’s problem(b)
    P4744 A’s problem(a)
    [bzoj] 1004: [HNOI2008]Cards
    NOIP2013 表达式求值
  • 原文地址:https://www.cnblogs.com/ohyee/p/5513869.html
Copyright © 2020-2023  润新知