Problem D: 勤奋的涟漪2 dp + 求导
2024-09-04 13:26:58
http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=3
dp[i][state]表示处理了前i个,然后当前状态是state的时候的最小休息天数。
比如用1代表休息,2是训练,3是运动。
如果当前这天允许的状态只是训练。
那么dp[i][3] = inf(表示不可能)
休息是无论何时都可能的了。从dp[i - 1][1--3]个状态转过来, + 1即可
那个求导是-24
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> const int maxn = + ;
int dp[maxn][];
void work() {
int n;
scanf("%d", &n);
memset(dp, , sizeof dp);
for (int i = ; i <= n; ++i) {
int x;
scanf("%d", &x);
if (x == ) {
dp[i][] = min(dp[i - ][], min(dp[i - ][], dp[i - ][])) + ;
dp[i][] = dp[i][] = inf;
} else if (x == ) {
dp[i][] = dp[i - ][];
dp[i][] = min(dp[i][], dp[i - ][]);
dp[i][] = min(dp[i - ][], min(dp[i - ][], dp[i - ][])) + ;
dp[i][] = inf;
} else if (x == ) {
dp[i][] = inf;
dp[i][] = min(dp[i - ][], dp[i - ][]);
dp[i][] = min(dp[i - ][], min(dp[i - ][], dp[i - ][])) + ;
} else if (x == ) {
dp[i][] = min(dp[i - ][], min(dp[i - ][], dp[i - ][])) + ;
dp[i][] = min(dp[i - ][], dp[i - ][]);
dp[i][] = min(dp[i - ][], dp[i - ][]);
}
}
int ans = inf;
for (int i = ; i <= ; ++i) {
ans = min(ans, dp[n][i]);
}
cout << ans * (-) << endl;
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
最新文章
- 在Nodejs中如何调用C#的代码
- appCan uexLocation 定位功能
- python 注意事项
- 根据指定Word模板生成Word文件
- log4net使用简明教程
- ArcGIS Desktop 与 Excel(转)
- struts2 修改action的后缀
- BZOJ_1003_[ZJOI2006]_物流运输_(动态规划+最短路)
- ng-html 报 不安全 警告解决办法
- 树莓派学习路程No.1 树莓派系统安装与登录 更换软件源 配置wifi
- CentOS 6.4源码编译安装httpd并启动测试
- 转delphi中nil的用法
- wxPython中按钮、文本控件的简单运用
- 跟我一起读postgresql源码(十)——Executor(查询执行模块之——Scan节点(下))
- Git更新代码到本地
- codecs and formats of digital media
- C++类中的静态成员变量和静态成员函数的作用
- Tomcat性能优化(三) Executor配置
- codeforces水题100道 第二十四题 Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings (strings)
- Spring Security中异常上抛机制及对于转型处理的一些感悟
热门文章
- jvm 命令
- sbt is a build tool for Scala, Java, and more
- Windows下VMware虚拟机使用Centos,Docker方式安装openstf的小坑
- I2S总线协议理解
- dedecms时间格式调用标签汇总
- MYSQL进阶学习笔记六:MySQL视图的创建,理解及管理!(视频序号:进阶_14,15)
- codeforces 448B. Suffix Structures 解题报告
- 一步一步学Silverlight 2系列(17):数据与通信之ADO.NET Data Services
- SideBar---fixed定位
- jquery实现无限滚动瀑布流实现原理