当前位置:网站首页>2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
2022-06-30 16:38:00 【Lovely and beautiful girl】
The question :
It's for you. n Bills , Each note has a time and price , You can choose some , Make the difference between any two dates of these bills >=k, Then make the total value closest to m, But not more than m.
reflection :
At that time, I used the definition of i What is the maximum number that this note can represent . There is a drawback to this , This will ensure maximum , But it may exceed m, exceed m Only special judgment , So this does not guarantee the closest m. So when it doesn't feel right , You can turn the total value into dp The state of , That is, enumerate to i A.m. , by j Whether the status can reach . And then transfer it . But the complexity is nnm, nearly 1e9. So it will time out , But you can get most of the points . So it can be optimized , The optimization point is that this date only has 365 God , therefore dp[i][j] For the first time i God j Whether the status can reach . Then for the enumeration of items, you can use a variable cnt Come and go straight back , The complexity is n*m+365 Of . Because each point only goes once, it only circulates n Time m. This complexity is enough .
Code :
Classical linear dp
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define PII pair<int,int >
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1005;
int T,n,m,k;
PII va[N];
int res[N],sum[N];
int dp[1010][5010];
signed main()
{
IOS;
cin>>n>>m>>k;
res[1] = 31,res[2] = 28,res[3] = 31,res[4] = 30;
res[5] = 31,res[6] = 30,res[7] = 31,res[8] = 31;
res[9] = 30,res[10] = 31,res[11] = 30,res[12] = 31;
for(int i=1;i<=12;i++) sum[i] = sum[i-1]+res[i];
for(int i=1;i<=n;i++)
{
int a,b,c;
cin>>a>>b>>c;
int now = sum[a-1]+b;
va[i] = {
now,c};
}
sort(va+1,va+1+n);
int cnt = 1;
dp[0][0] = 1;va[0].fi = -100;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=m;j++) dp[i][j] |= dp[i-1][j];
for(int j=0;j<i;j++)
{
for(int t=va[i].se;t<=m;t++)
{
if(va[i].fi-va[j].fi>=k)
dp[i][t] |= dp[j][t-va[i].se];
}
}
}
int maxn = 0;
for(int i=m;i>=0;i--)
{
if(dp[n][i])
maxn = max(maxn,i);
}
cout<<maxn;
return 0;
}
Convert to status after optimization dp
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define PII pair<int,int >
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1005;
int T,n,m,k;
PII va[N];
int res[N],sum[N];
int dp[1010][5010];
signed main()
{
IOS;
cin>>n>>m>>k;
res[1] = 31,res[2] = 28,res[3] = 31,res[4] = 30;
res[5] = 31,res[6] = 30,res[7] = 31,res[8] = 31;
res[9] = 30,res[10] = 31,res[11] = 30,res[12] = 31;
for(int i=1;i<=12;i++) sum[i] = sum[i-1]+res[i];
for(int i=1;i<=n;i++)
{
int a,b,c;
cin>>a>>b>>c;
int now = sum[a-1]+b;
va[i] = {
now,c};
}
sort(va+1,va+1+n);
int cnt = 1;
dp[0][0] = 1;
for(int i=1;i<=365;i++)
{
for(int j=0;j<=m;j++) dp[i][j] |= dp[i-1][j];
while(cnt<=n&&va[cnt].fi==i)
{
for(int j=0;j<=m;j++)
{
if(i>=k&&j>=va[cnt].se) dp[i][j] |= dp[i-k][j-va[cnt].se];
else if(i<k&&j==va[cnt].se) dp[i][j] |= 1;
}
cnt++;
}
}
int maxn = 0;
for(int i=m;i>=0;i--)
{
if(dp[365][i])
maxn = max(maxn,i);
}
cout<<maxn;
return 0;
}
summary :
Think more , Think about similar solutions and optimizations .
边栏推荐
- 荣盛生物冲刺科创板:拟募资12.5亿 年营收2.6亿
- Cesium-1.72 learning (add points, lines, cubes, etc.)
- Table responsive layout tips for super nice
- [CVE-2019-0193] - Apache Solr DataImport 远程命令执行分析
- Build cloud native observability capability suitable for organizations
- What role does "low code" play in enterprise digital transformation?
- 备战数学建模36-时间序列模型2
- 招标公告:2022年台州联通Oracle一体机和数据库维保服务项目
- [algorithm] after summarizing the four linked lists, I brushed two interview questions
- Log4j2 进阶使用
猜你喜欢

婴儿认知学习所带来的启发,也许是下一代无监督机器学习的关键

The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning

How cloudxr promotes the future development of XR

中国传奇教授李泽湘,正在批量制造独角兽

BC1.2 PD协议

What is the difference between real-time rendering and pre rendering
Mysql8.0 method and steps for enabling remote connection permission

今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计

RT-Thread 堆区大小设置

Under the pressure of technology, you can quickly get started with eth smart contract development, which will take you into the ETH world
随机推荐
中航无人机科创板上市:市值385亿 拳头产品是翼龙无人机
The new tea drinks are "dead and alive", but the suppliers are "full of pots and bowls"?
附加:(还没写,别看~~~)WebMvcConfigurer接口;
2022蓝桥杯国赛B组-2022-(01背包求方案数)
Explain in detail the use of for loop, break and continue in go language
【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
备战数学建模36-时间序列模型2
MySQL transaction / lock / log summary
Implementation of Devops in the core field of qunar, the Internet R & D Efficiency
KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
Headhunter 50, 000, I'll go to VC
附加:(还没写,别看~~~)CorsFilter过滤器;
Three development trends of enterprise application viewed from the third technological revolution
halcon知识:矩阵专题【02】
RT thread heap size setting
ArcMap operation series: 80 plane to latitude and longitude 84
优惠券种类那么多,先区分清楚再薅羊毛!
CloudXR如何推动XR的未来发展
[machine learning] K-means clustering analysis
MC Instruction Decoder