蓝桥杯 振兴中华(简单dp)

题目

从我做起振
我做起振兴
做起振兴中
起振兴中华

四连通,从左上角出发到右下角

求"从我做起振兴中华"的方案数

思路来源

https://blog.csdn.net/qq_33302004/article/details/79632132

题解

网上一堆搜索代码长得GG

这明明是个填空题,自己也填出了35

但感觉这种题总是不稳,还是总结一下经验

和立刻出行杯一个按对角线遍历的题很像

当然也可以按行按列扫

代码1

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll dp[6][6];
bool check(int x,int y)
{
	return x>=1&&x<=4&&y>=1&&y<=5;
}
int main()
{
	dp[1][1]=1;
	for(int len=3;len<=9;++len)
	{
		for(int r=1;r<=min(4,len-1);++r)
		{
			int c=len-r;
			if(check(r-1,c))dp[r][c]+=dp[r-1][c];
			if(check(r,c-1))dp[r][c]+=dp[r][c-1];
		}
	}
	printf("%lld\n",dp[4][5]);
	return 0;
} 

代码2

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int dp[5];
int main()
{
	//dp[i][j]=dp[i][j-1]+dp[i-1][j]
	//化简得,i增序,j增序 dp[j]+=dp[j-1]
	//行增序dp即可 
	for(int j=0;j<=4;++j)dp[j]=1;
	for(int i=1;i<=3;++i)
	{
		for(int j=1;j<=4;++j)
		dp[j]+=dp[j-1];
	} 
	printf("%d\n",dp[4]);
	return 0;
} 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code92007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值