关于P8707的方法
这是我某个团队题单里面的一道题。
P8707:
首先看一下题目:
P8707,
我们其实可以把这道题看成一道数学题。就像规划路径一样,因为只能向右、下方走,所以我们就可以用
这是常规的数学题方法,但是,题目中要求,如果
所以,代码就可以写出来了:
首先,要定义
#include <bits/stdc++.h>
using namespace std;
int n,m,a[33][33];
int main()
{
cin >> n >> m;
return 0;
}
然后,就要开始一格一格的计算了,具体是这样(旁边有注释):
#include<bits/stdc++.h>
using namespace std;
int n,m,a[33][33];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
a[1][1] = 1; //起点是1
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= m;j++)
{
if(i == 1 && j == 1) continue; //如果是(i,j)是起点,continue
if(i % 2 == 0 && j % 2 == 0) continue; //如果i和j都是偶数,continue
a[i][j] = a[i - 1][j] + a[i][j - 1]; //到达(i,j)的路径数等于该点上面的路径数加上该点左边的路径数
}
}
cout << a[n][m]; //输出终点的路径数
return 0;
}
!!!!!!!!!!!!!完 !!!!!!!!!!!!