当前位置:网站首页>Treasure taking from underground palace (memory based deep search)
Treasure taking from underground palace (memory based deep search)
2022-07-01 06:11:00 【Great intelligence】
Portal
Title Description
X The king has a treasure house . yes n x m Matrix of lattice . One treasure per cell . Every baby has a value tag .
The entrance to the underground palace is in the upper left corner , The exit is in the lower right corner .
Xiaoming is taken to the entrance of the underground palace , The king asked him to walk only to the right or down .
When walking through a grid , If the treasure in that lattice is worth more than any treasure in Xiaoming's hand , Xiaoming can pick it up ( Of course , Or not ).
When Xiaoming comes to the exit , If the baby in his hand happens to be k Pieces of , Then these babies can be given to Xiao Ming .
Input format
The input line 3 It's an integer , Separate with spaces :n m k (1<=n,m<=50, 1<=k<=12)
Next there is n Row data , Each row has m It's an integer Ci (0<=Ci<=12) Represents the value of the treasure on this grid
Output format
An integer is required , It means just take k Number of action plans for each baby . The number could be large , Export it to 1000000007 Results of die taking .
sample input
2 2 2
1 2
2 1
sample output
2
analysis : Yes 1000000007 Taking a mold indicates that there is a large amount of data , Use long long Type and memory deep search ;
1、 All baby value plus 1: Because the initial value may be 0,maxn Cannot also be 0 The comparison in the function is changed to >= That's not right. ( It is required that the baby you find is more expensive than the previous one )maxn by -1 Not good either. Array cannot be negative , So we need to add 1 So the minimum initial value is 1 They don't influence each other
2、 Every time ans Initialize to 0, We have reached a certain point , Each subsequent step corresponds to several situations , therefore dp Represents this step , How many situations can it correspond to , This gradually accumulates , all return The starting point of the last step ans Is the general situation
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1000000007;
ll a[55][55];
ll dp[55][55][15][15];
ll n,m,k;
ll dfs( ll x,ll y,ll maxn,ll t)
{
ll ans=0;
if(t>k||x>n||y>m) return 0;
if(dp[x][y][maxn][t]!=-1)
return dp[x][y][maxn][t];
if(x==n&&y==m)
{
if( t==k || (t==k-1&&a[x][y]>maxn) )
return 1;
return 0;
}
if(a[x][y]>maxn)// Pick up the baby
{
ans+=dfs(x+1,y,a[x][y],t+1);
ans+=dfs(x,y+1,a[x][y],t+1);
}
ans+=dfs(x+1,y,maxn,t);
ans+=dfs(x,y+1,maxn,t);
// When you meet the right baby, you can pick it up , There are also cases where it is not necessary to pick up , So we have to go through the situation of not picking up
ans%=mod;
dp[x][y][maxn][t]=ans;
return ans;
}
int main()
{
scanf("%lld%lld%lld",&n,&m,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
scanf("%lld",&a[i][j]);
a[i][j]+=1;
}
memset(dp,-1,sizeof(dp));
printf("%lld\n",dfs(1,1,0,0)%mod);
}
边栏推荐
- 69 Cesium代码datasource加载geojson
- 数据库问题,如何优化Oracle SQL查询语句更快,效率更高
- Differences between in and exists in MySQL
- 3D打印机穿线:5种简单的解决方案
- Code shoe set - mt3114 · interesting balance - explain it with examples
- Huluer app help
- Save data in browser to local file
- 表格中el-tooltip 实现换行展示
- Using Baidu map to query national subway lines
- 指数法和Random Forest实现山东省丰水期地表水体信息
猜你喜欢

Multi label lsml for essay learning records

CJC8988带2个立体声耳机驱动器的低功率立体声编解码器

PLA不粘贴在床上:6个简单的解决方案

Essay learning record essay multi label Global

jdbc 数据库操作

Pla ne colle pas sur le lit: 6 solutions simples

指数法和Random Forest实现山东省丰水期地表水体信息

Arcserver password reset (account cannot be reset)

π disk, turning your computer into a personal private cloud

Database problems, how to optimize Oracle SQL query statements faster and more efficient
随机推荐
Save data in browser to local file
HDU - 1501 Zipper(记忆化深搜)
π disk, turning your computer into a personal private cloud
Don't put your notes and videos everywhere!
Flink实战--多流合并
SystemVerilog学习-09-进程间同步、通信和虚方法
Know the future of "edge computing" from the Nobel prize!
Code shoe set - mt3149 · and - the data is not very strong. Violent pruning can deceive AC
1034 Head of a Gang
阶乘约数(唯一分解定理)
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
机械臂速成小指南(六):步进电机驱动器
TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)
Fragment upload and breakpoint resume
Infinite horizontal marble game
栈题目:解析布尔表达式
srpingboot security demo
XAF Bo of dev XPO comparison
SystemVerilog学习-10-验证量化和覆盖率
ABP 学习解决方案中的项目以及依赖关系