当前位置:网站首页>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);
}
边栏推荐
- SystemVerilog学习-09-进程间同步、通信和虚方法
- OpenGL ES: (1) OpenGL ES的由来 (转)
- Oracle sequence + trigger
- 基于LabVIEW的计时器
- DHT11 温湿度传感器
- Seven major technical updates that developers should pay most attention to on build 2022
- MinIO纠错码、分布式MinIO集群搭建及启动
- How to add a gourd pie plate
- Excel dynamic chart
- Transformer le village de tiantou en un village de betteraves sucrières
猜你喜欢

What if the data in the cloud disk is harmonious?

TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)

Thesis learning record essay multi label lift

el-table 动态表头渲染 固定第一列 高度问题

相同区域 多源栅格数据 各个像元行列号一致,即行数列数相同,像元大小相同

Essay learning record essay multi label Global

three.js小结

Infinite horizontal marble game

Skywalking integrated Nacos dynamic configuration

The row and column numbers of each pixel of multi-source grid data in the same area are the same, that is, the number of rows and columns are the same, and the pixel size is the same
随机推荐
ArcServer密码重置(账号不可以重置)
El tooltip in the table realizes line breaking display
DEV XPO对比之UOW
地宫取宝(记忆化深搜)
jdbc-连接池
Call us special providers of personal cloud services for College Students
three. JS summary
kotlin位运算的坑(bytes[i] and 0xff 报错)
【文件系统】如何在ubi之上运行squashfs
MongoDB:一、MongoDB是什么?MongoDB的优缺点
Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills
Transformer le village de tiantou en un village de betteraves sucrières
DHT11 温湿度传感器
Freeswitch dial the extension number
Why use huluer pie disk instead of U disk?
无限水平大理石游戏
Save data in browser to local file
[note] e-commerce order data analysis practice
MySQL中 in 和 exists 的区别
Highmap gejson data format conversion script