当前位置:网站首页>2039: [Bluebridge cup 2022 preliminaries] Li Bai's enhanced version (dynamic planning)
2039: [Bluebridge cup 2022 preliminaries] Li Bai's enhanced version (dynamic planning)
2022-07-07 05:09:00 【Madness makes freedom】
Title Description
On the great poet Li Bai , Good drink for life . Fortunately, he never drives .
One day , He's carrying a jug , Come out of the house , There is wine in the wine pot 2 Bucket . He sang as he walked :
Walk on the street , Pick up the pot and go get the wine .
Double for every shop , Have a drink with flowers .
This way , He met the store N Time , Encounter flowers M Time .
We know that the last time we met was flowers , He just finished his drink .
Please calculate the order of shops and flowers Li Bai meets along the way , How many different possibilities ?
Be careful : There is no wine in the pot ( 0 Bucket ) Shiyu store is legal , There is still no wine after doubling ; But it's illegal to meet flowers without wine .Input format
Input contains multiple sets of test data .
First act T, Indicates presence T Group test data ,T No more than 30.
For each group of test data , Enter two integers N and M.
1 ≤ N, M ≤ 100.Output format
Output an integer for the answer . Because the answer can be big , Output mode 1000000007 Result .
sample input Copy
1 5 10
sample output Copy
14
It was not written at first , Think of depth first search , That is, the second code , You can't AC, See others' recommendations later , Just know Yan xuecan (y total )(acwing The founder of the website , There are many classes , I believe it is necessary to have a look , Slowly learn the data structure , You have to be prepared CCF Of CSP Certified ), I watched him talk about the preliminary match of the Blue Bridge Cup , Just understand , It can also be seen from the side , I'm weak ,emm, exactly , The revolution has not yet succeeded , I have to keep trying .
analysis :
State Design :dp[i][j][k] The value of indicates that i stores ,j A flower , There is still something left in the wine pot k The number of possible cases of fighting alcohol ;
State transition equation :dp[i][j][k]=dp[i-1][j][k/2](i>1&&k%2==0) + dp[i][j-1][k+1](j>1);
Boundary design : except dp[0][0][2]=1, All the other elements are 0;
He met the store N Time , Encounter flowers M Time . We know that the last time we met was flowers , He just finished his drink ; therefore
The last time I must encounter flowers , Then the final result is dp[N][M-1][1];
And the volume of wine in the wine pot cannot exceed M;
/**
Recode :
State Design :dp[i][j][k] The value of indicates that i stores ,j A flower , There is still something left in the wine pot k The number of possible cases of fighting alcohol ;
State transition equation :dp[i][j][k]=dp[i-1][j][k/2](i>1&&k%2==0) + dp[i][j-1][k+1](j>1);
Boundary design : except dp[0][0][2]=1, All the other elements are 0;
He met the store N Time , Encounter flowers M Time . We know that the last time we met was flowers , He just finished his drink ; therefore
The last time I must encounter flowers , Then the final result is dp[N][M-1][1];
And the volume of wine in the wine pot cannot exceed M;
*/
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1000000007;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
int dp[n+1][m+1][m+1];
memset(**dp,0,sizeof(dp));
dp[0][0][2]=1;
for(int i=0;i<=n;++i)
for(int j=0;j<=m;++j)
for(int k=0;k<=m;++k)
{
int &val=dp[i][j][k];
if(i>=1&&k%2==0)
val=(val+dp[i-1][j][k/2])%mod;
if(j>=1)
val=(val+dp[i][j-1][k+1])%mod;
}
printf("%d\n",dp[n][m-1][1]);
}
return 0;
}
DFS solve
Can only AC 13%, Have to say , For a question , Unable to find the correct algorithm strategy and the correct algorithm strategy
Compare , It's a big difference ;
/**
DFS solve
Can only AC 13%, Have to say , For a question , Unable to find the correct algorithm strategy and the correct algorithm strategy
Compare , It's a big difference ;
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int mod=1000000007;
void drink_DFS(int store,int flow,int drink);
int sum=0,N,M;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
sum=0;
scanf("%d%d",&N,&M);
drink_DFS(0,0,2);
printf("%d\n",sum);
}
return 0;
}
void drink_DFS(int store,int flow,int drink)
{
if(drink < 0) return;
if(store > N || flow >= M) return;
if(drink>M) return;
if(store==N&&flow==M-1&&drink==1)
{
sum+=1;
sum%=mod;
return;
}
drink_DFS(store+1,flow,2*drink);
drink_DFS(store,flow+1,drink-1);
// store+=1;
// drink*=2;
// drink_DFS(store,flow,drink);
// store-=1;
// drink/=2;
// flow+=1;
// drink-=1;
// drink_DFS(store,flow,drink);
// flow-=1;
// drink+=1;
}
边栏推荐
- Time complexity & space complexity
- Talk about the importance of making it clear
- Mysql database (basic)
- SQL injection - secondary injection and multi statement injection
- 基于Bevy游戏引擎和FPGA的双人游戏
- U++4 接口 学习笔记
- Clickhouse (03) how to install and deploy Clickhouse
- Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot microservice code analysis and dialogue experim
- PMP证书有没有必要续期?
- 史上最全学习率调整策略lr_scheduler
猜你喜欢
A simple and beautiful regression table is produced in one line of code~
Leetcode(417)——太平洋大西洋水流问题
Common Oracle SQL statements
Ansible overview and module explanation (you just passed today, but yesterday came to your face)
基于Bevy游戏引擎和FPGA的双人游戏
[email protected]映射关系问题"/>
接口间调用为什么要用json、fastjson怎么赋值的、fastjson [email protected]映射关系问题
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
使用知云阅读器翻译统计遗传学书籍
C语言中函数指针与指针函数
【二叉树】二叉树寻路
随机推荐
AOSP ~Binder 通信原理 (一) - 概要
Weebly mobile website editor mobile browsing New Era
01 machine learning related regulations
Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
App embedded H5 --- iPhone soft keyboard blocks input text
[736. LISP syntax parsing]
【愚公系列】2022年7月 Go教学课程 005-变量
与利润无关的背包问题(深度优先搜索)
JS 的 try catch finally 中 return 的执行顺序
Ansible概述和模块解释(你刚走过了今天,而扑面而来的却是昨天)
Error: No named parameter with the name ‘foregroundColor‘
Leetcode longest public prefix
最长回文子串(动态规划)
U++ metadata specifier learning notes
Comparison between thread and runnable in creating threads
DBSync新增对MongoDB、ES的支持
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
STM32F103实现IAP在线升级应用程序
Leetcode(417)——太平洋大西洋水流问题
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践