当前位置:网站首页>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 10sample 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;
}边栏推荐
- 史上最全学习率调整策略lr_scheduler
- np.random.shuffle与np.swapaxis或transpose一起时要慎用
- STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
- Talk about the importance of making it clear
- When knative meets webassembly
- DBSync新增对MongoDB、ES的支持
- 【愚公系列】2022年7月 Go教学课程 005-变量
- National meteorological data / rainfall distribution data / solar radiation data /npp net primary productivity data / vegetation coverage data
- 全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
- 2. Overview of securities investment funds
猜你喜欢

Weebly移动端网站编辑器 手机浏览新时代

SQL injection - secondary injection and multi statement injection

如何设计 API 接口,实现统一格式返回?

offer如何选择该考虑哪些因素

ThinkPHP关联预载入with

Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.

Weebly mobile website editor mobile browsing New Era

If you‘re running pod install manually, make sure flutter pub get is executed first.

Basic knowledge of road loss of 3GPP channel model

SQL injection HTTP header injection
随机推荐
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
File upload vulnerability summary
A simple and beautiful regression table is produced in one line of code~
qt 简单布局 盒子模型 加弹簧
Why JSON is used for calls between interfaces, how fastjson is assigned, fastjson 1.2 [email protected] Mapping relatio
【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
如何设计 API 接口,实现统一格式返回?
线程同步的两个方法
Ansible overview and module explanation (you just passed today, but yesterday came to your face)
【愚公系列】2022年7月 Go教学课程 005-变量
AOSP ~Binder 通信原理 (一) - 概要
When knative meets webassembly
指针与数组在函数中输入实现逆序输出
3GPP信道模型路损基础知识
Leetcode(46)——全排列
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
动态生成表格
Understand common network i/o models
Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
U++ 游戏类 学习笔记