HzuWHF


私信TA

用户名:I7I08I9047

访问量:77147

签 名:

我RUN了

等  级
排  名 18
经  验 20536
参赛次数 13
文章发表 127
年  龄 3
在职情况 学生
学  校 贺州学院
专  业

  自我简介:

解题思路:

        搜索 + DP。

参考代码:

#include<bits/stdc++>h>
using namespace std;

const int MOD = 1000000007;
int Map[52][52];
int status[52][52][14][14];
int Maph, Mapw, quan;

int DFS(int posx, int posy, int total, int Maxvalue) {
	if (status[posx][posy][total][Maxvalue] != -1)
		return status[posx][posy][total][Maxvalue];
		
	if (posx == Maph && posy == Mapw) {
		if ((total == quan) || (total == quan - 1 && Map[Maph][Mapw] > Maxvalue))
			return status[posx][posy][total][Maxvalue] = 1;
		return status[posx][posy][total][Maxvalue] = 0;
	}

	int cnt = 0;
	if (posx < Maph) {
		if (Map[posx][posy] > Maxvalue)
			cnt = (cnt + DFS(posx + 1, posy, total + 1, Map[posx][posy])) % MOD;
		cnt = (cnt + DFS(posx + 1, posy, total, Maxvalue)) % MOD;
	}
	if (posy < Mapw) {
		if (Map[posx][posy] > Maxvalue)
			cnt = (cnt + DFS(posx, posy + 1, total + 1, Map[posx][posy])) % MOD;
		cnt = (cnt + DFS(posx, posy + 1, total, Maxvalue)) % MOD;
	}
	
	return status[posx][posy][total][Maxvalue] = cnt % MOD;
}

int main() {
	scanf("%d%d%d", &Maph, &Mapw, &quan);
	memset(status, -1, sizeof(status));
	for (int i1 = 1; i1 <= Maph; i1++)
		for (int i2 = 1; i2 <= Mapw; i2++) {
			scanf("%d", &Map[i1][i2]);
			Map[i1][i2]++;
		}
	printf("%d\n", DFS(1, 1, 0, 0));
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区