OR172. Shopee的办公室(二)
描述
输入描述
第一行 x,y,n (0<x<=30, 0<y<=30, 0<=n<= 20) 表示x,y小虾的座位坐标,n 表示boss的数量( n <= 20)输出描述
输出小虾有多少种走法示例1
输入:
3 3 2 1 1 2 2
输出:
4
C 解法, 执行用时: 2ms, 内存消耗: 332KB, 提交时间: 2020-07-26
#include <stdio.h> int main() { int x, y, n; scanf("%d %d %d", &x, &y, &n); int mm[31][31] = {0}; int inputx, inputy; for(int i = 0; i < n; i++) { scanf("%d %d", &inputx, &inputy); mm[inputx][inputy] = 1; } long nn[31][31] = {0}; nn[0][0] = 1; for(int i = 0; i <= x; i++) { for(int j = 0; j <= y; j++) { if(mm[i][j] == 1) { nn[i][j] = 0; } else { if(i >= 1) nn[i][j] += nn[i - 1][j]; if(j >= 1) nn[i][j] += nn[i][j - 1]; } } } printf("%ld\n", nn[x][y]); return 0; }
C 解法, 执行用时: 2ms, 内存消耗: 360KB, 提交时间: 2020-05-12
int main(){ int n,m,b; scanf("%d %d %d", &n, &m, &b); int i,j,k; int x,y; long long a[33][33] = {0}; for (i=0;i<b;i++){ scanf("%d %d", &x, &y); a[x][y] = -1; } if (a[0][0] == -1) printf("0"); else { a[0][0] = 1; for (i=1;i<=n;i++){ if (a[i][0] != -1) a[i][0] = a[i-1][0]; } for (j=1;j<=m;j++){ if (a[0][j] != -1) a[0][j] = a[0][j-1]; } for (i=1; i<=n; i++) for (j=1; j<=m; j++) { if (a[i][j] != -1) { if (a[i-1][j] != -1) a[i][j] +=a[i-1][j]; if (a[i][j-1] != -1) a[i][j] +=a[i][j-1]; } } if (a[n][m] != -1) printf("%lld", a[n][m]); } return 0; }