#include <bits/stdc++.h>
using namespace std;
int a[]={0,1};
int b[]={1,0};
int cnt;
void dfs(int x,int y){
if(x==3&&y==4)\\因为[1,1]和[4.5]是固定的,所以变化量就只有剩下三行和四列
cnt++;
for(int i=0;i<2;i++){
int dx,dy;
dx=x+a[i];
dy=y+b[i];
if(x<=3&&y<=4)
dfs(dx,dy);\\线性坐标
}
}
int main()
{
dfs(0,0);
cout<<cnt;
return 0;
}
递归迭代,下面这个解法的主体部分略显抽象,貌似还没学过,也有可能学过了是我忘了,/*里的内容是百度的
#include <iostream>
using namespace std;
int f(int x, int y)
{ //状态
if(x == 3 || y == 4)
{
return 1;
}
return f(x+1, y) + f(x, y+1); //重复
}
int main(int argc, char** argv)/*
argc:命令行参数个数(Argument Count)
argv:命令行参数向量(Argument Vector)
例如,我们在命令行输入Project.exe string1 string2 string3时,argc=4,表示输入的参数个数是4,分别是Project.exe、string1、string2、string3。
argv是一个字符串数组,对应存储这4个字符串,即argv[0] = "Project.exe", argv[1] = "string1", argv[2] = "string2", argv[3] = "string3"*/
{
cout << f(0, 0) << endl;
return 0;
}
0.0分
0 人评分
C二级辅导-公约公倍 (C语言代码)浏览:2122 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:732 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:968 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:904 |
程序员的表白 (C语言代码)浏览:666 |
大神老白 (C语言代码)浏览:645 |
WU-输出九九乘法表 (C++代码)浏览:1671 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:506 |
P1000 (C语言代码)浏览:877 |
剪刀石头布 (C++代码)浏览:1711 |