• 题意:有\(n\)个菜在烤箱中,每个时刻只能将一个菜从烤箱中拿出来,第\(i\)个时刻拿出来的贡献是\(|i-a[i]|\),你可以在任意时刻把菜拿出来,问将所有菜拿出的最小贡献是多少?

  • 题解: 先对所有菜从小到大排序,因为\(a_i\)单调,我们可以枚举时刻\([1,2*n]\)来进行DP,先更新第一道菜的状态,然后再更新后面的状态,每道菜可以由当前时刻之前的前一道菜的状态转移而来,所以写出状态转移方程:\(dp[i][j]=min(dp[i-1][k]+abs(j-a[i]),dp[i][j])\).

  • 题解:

    int t;
    int n;
    int a[N];
    int dp[4000][4000];
    int ans; int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
    cin>>n;
    ans=INF;
    for(int i=1;i<=n;++i) cin>>a[i];
    sort(a+1,a+1+n);
    me(dp,INF,sizeof(dp));
    for(int i=1;i<=4*n;++i) dp[1][i]=abs(i-a[1]);
    for(int i=2;i<=n;++i){
    for(int j=i;j<=4*n;++j){
    for(int k=1;k<j;++k){
    dp[i][j]=min(dp[i-1][k]+abs(j-a[i]),dp[i][j]);
    }
    }
    }
    for(int i=1;i<=4*n;++i) ans=min(ans,dp[n][i]);
    cout<<ans<<endl;
    } return 0;
    }

Educational Codeforces Round 97 (Rated for Div. 2) C. Chef Monocarp (DP)的更多相关文章

  1. Educational Codeforces Round 97 (Rated for Div. 2)

    补了一场Edu round. A : Marketing Scheme 水题 #include <cstdio> #include <algorithm> typedef lo ...

  2. Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...

  3. Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)

    题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...

  4. Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree (贪心)

    题意:有一个从根节点\(BFS\)得来的序列(每次\(bfs\)子节点的时候保证是升序放入队列的),现在让你还原树(没必要和之前相同),问能构造出的最小的树的深度. 题解:不看根节点,我们从第二个位置 ...

  5. Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)

    #include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char ...

  6. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp

    E. The Contest A team of three programmers is going to play a contest. The contest consists of

  7. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  9. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. Tomcat配置上遇到的一些问题

    Tomcat启动:在bin目录下双击startup.bat文件就行. 访问:在浏览器输入http://localhost:8080 回车访问的是自己 的界面: http://othersip:8080 ...

  2. Nginx 安装与配置教程

    标签: Nginx Linux Windows 配置 描述: Ubuntu 下以及 Windows 下 Nginx 的配置:配置详解:有关 Nginx 如何配置 Nginx 在 Ubuntu 下的安装 ...

  3. Netty源码解析 -- FastThreadLocal与HashedWheelTimer

    Netty源码分析系列文章已接近尾声,本文再来分析Netty中两个常见组件:FastThreadLoca与HashedWheelTimer. 源码分析基于Netty 4.1.52 FastThread ...

  4. QA职责

  5. VS2019项目docker启动且访问SQLSERVER数据库配置

    VS2019编译.调试的Blazor纯前台项目,使用控制台启动,去连接纯后台的API项目,使用docker启动,并且通过EFCore访问SQLSERVER数据库,有几个地方需要修改配置: 一.前台连后 ...

  6. JMS监听Oracle AQ

    该文档中,oracle版本为11g,jdk版本1.8,java项目为maven构建的springboot项目,springboot的版本为2.1.6,并使用了定时任务来做AQ监听的重连功能,解决由于外 ...

  7. centos7.4使用filrewalld打开关闭防火墙与端口

    1.firewalld的基本使用启动: systemctl start firewalld关闭: systemctl stop firewalld查看状态: systemctl status fire ...

  8. Vijos-P1103题解【线段树】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: https://www.vijos.org/p/1103 题目描述: 一条马路从数轴0到L,每 ...

  9. Ubuntu20.04安装Typora

    Ubuntu20.04安装Typora 安装方法 # optional, but recommended sudo apt-key adv --keyserver keyserver.ubuntu.c ...

  10. Git 创建新分支检查分支

    创建分支和切换分支,也可以称为检出分支 创建新分支 git branch branchName 切换到新分支 git checkout branchName 上面两个命令也可以合成为一个命令: git ...