当前位置:网站首页>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);
}
边栏推荐
- 数据库问题,如何优化Oracle SQL查询语句更快,效率更高
- TIDB数据库特性总结
- Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432
- Diffusion (multi-source search)
- jdbc 数据库操作
- Freeswitch dial the extension number
- Understanding of C manualresetevent class
- Solve the problem of garbled files uploaded by Kirin v10
- 【文件系统】如何在ubi之上运行squashfs
- 论文学习记录随笔 多标签之GLOCAL
猜你喜欢

LED lighting used in health lighting

El tooltip in the table realizes line breaking display
![kotlin位运算的坑(bytes[i] and 0xff 报错)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
kotlin位运算的坑(bytes[i] and 0xff 报错)

π disk, turning your computer into a personal private cloud

蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是

C language beginner level - realize the minesweeping game

Know the future of "edge computing" from the Nobel prize!

Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432

Database problems, how to optimize Oracle SQL query statements faster and more efficient

OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow
随机推荐
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
浏览器端保存数据到本地文件
UOW of dev XPO comparison
讓田頭村變甜頭村的特色農產品是仙景芋還是白菜
Factorial divisor (unique decomposition theorem)
HDU - 1501 Zipper(记忆化深搜)
Through cooperation with the University of international trade, we can increase efficiency for college students
Bat operation FTP upload and download command
利用百度地图查询全国地铁线路
el-table 动态表头渲染 固定第一列 高度问题
Preliminary level of C language -- selected good questions on niuke.com
2022 年面向初学者的 10 大免费 3D 建模软件
Make: g++: command not found
ONEFLOW source code parsing: automatic inference of operator signature
[note] e-commerce order data analysis practice
Highmap gejson data format conversion script
OpenGL es: (2) relationship between OpenGL es, EGL and glsl
XAF Bo of dev XPO comparison
Essay learning record essay multi label Global
Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills