2019DX#1
1001 Blank
题意
有一个长度为n(n<=100)的位子,填入四种颜色,有m个限制,某个区间的颜色个数要恰好等于x个。问颜色个数的方案数。
思路
DP
四维的DP,利用滚动数组优化一维空间。
我觉得这个构造的还是比较巧妙的。四维,每一维代表每个颜色最后出现的位子。
保证(i < j < k < L),这样每次向后L增大一位,可以从i,j,k,l四种情况转移而来。
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; /**********showtime************/ const int maxn = ;
vector<pii> v[maxn];
ll dp[maxn][maxn][maxn][];
int main(){
int T; scanf("%d", &T);
while(T--) {
int n,m;
scanf("%d%d", &n, &m);
for(int i=; i<=n; i++) v[i].clear();
for(int i=; i<=m; i++) {
int le, ri, c;
scanf("%d%d%d", &le, &ri, &c);
v[ri].pb(pii(le, c));
}
memset(dp, , sizeof(dp));
dp[][][][] = ;
ll ans = ;
int cur = ;
for(int l=; l<=n; l ++) {
for(int i=; i<=l; i++) {
for(int j=i ? i+:; j<=l; j++) {
for(int k=j?j+:; k<=l; k++ ){ for(pii p : v[l]) {
int le = p.fi, ri = l, c = p.se; if(c == ) {
if(k >= le) {dp[i][j][k][cur] = ;break;}
} else if(c == ) {
if(j >= le || k < le) {dp[i][j][k][cur] = ;break;}
}
else if(c == ) {
if(i>=le || j < le) {dp[i][j][k][cur] = ;break;}
}
else {
if(i < le) {dp[i][j][k][cur] = ;break;}
}
}
dp[j][k][l][cur^] = (dp[j][k][l][cur^] + dp[i][j][k][cur]) % mod; dp[i][k][l][cur^] = (dp[i][k][l][cur^] + dp[i][j][k][cur]) % mod; dp[i][j][l][cur^] = (dp[i][j][l][cur^] + dp[i][j][k][cur]) % mod; dp[i][j][k][cur^] = (dp[i][j][k][cur^] + dp[i][j][k][cur]) % mod;
if(l == n) ans = (ans + dp[i][j][k][cur]) % mod;
}
}
}
for(int i=; i<=l; i++)
for(int j=i ? i+:; j<=l; j++)
for(int k=j?j+:; k<=l; k++ )
dp[i][j][k][cur] = ;
cur = cur ^ ; }
printf("%lld\n", ans);
} return ;
}
1002 Operation
线性基
1003 Milk
背包
1004 Vacation
题意:
•有n(n <= 100000)辆车,依次排在一个红绿灯口,(单车道,且直行,不能超车)
•每辆车都有一个最大速度,车长,距离红绿灯线的距离。
•问最后一辆车头碰到红绿灯线的最短时间。
思路:
可以贪心做,当然二分时间也可以。赛后补了下二分的写法
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; /**********showtime************/ const int maxn = 1e5+;
int l[maxn],s[maxn],v[maxn];
int n; bool check(double t) {
double pos = -inff;
for(int i=n; i>=; i--) {
double tp = 1.0*s[i] - t * v[i];
pos = max(pos, tp);
if(i)pos += l[i];
}
return pos < ;
}
int main(){
while(~scanf("%d", &n)) {
for(int i=; i<=n; i++) {
scanf("%d", &l[i]);
}
for(int i=; i<=n; i++) {
scanf("%d", &s[i]);
}
for(int i=; i<=n; i++) {
scanf("%d", &v[i]);
}
double le = , ri = , res;
for(int i=; i<=; i++) {
double mid = (le + ri) / ;
if(check(mid)) ri = mid, res = mid;
else le = mid;
}
printf("%.10f\n", res);
} return ;
}
1006 Typewriter
后缀自动机
1007 Meteor
1010 Kingdom
记忆化搜索
1011 Function
化公式
1012 Sequence
ntt
1013 Code
转成凸包,或者lzh大法。
2019DX#1的更多相关文章
- 2019DX#10
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Minimum Spanning Trees 22.22%(2/9) 1002 Lin ...
- 2019dx#9
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Rikka with Quicksort 25.85%(38/147) 1002 Ri ...
- 2019DX#8
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Acesrc and Cube Hypernet 7.32%(3/41) 1002 A ...
- 2019dx#7
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 A + B = C 10.48%(301/2872) 1002 Bracket Seq ...
- 2019DX#6
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Salty Fish 16.28%(7/43) OK 1002 Nonsense Tim ...
- 2019DX#5
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 fraction 辗转相除 4.17%(7/168) ok 1002 three arr ...
- 2019dx#4
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 AND Minimum Spanning Tree 31.75%(1018/3206) ...
- 2019DX#3
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Azshara's deep sea 凸包 6.67%(6/90)
- 2019DX#2
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Another Chess Problem 8.33%(1/12) 1002 Beau ...
随机推荐
- Cordova-iOS SDK封装
源码编译与制作静态库 下载cordova-ios源码,下载地址为:cordova-ios 解压后使用Xcode进行编译,编译选定模拟器和Generic iOS Device,cmd+B,编译成功(Dy ...
- codeforces 355A Vasya and Digital Root
题意就是找出一个长度为k的整数,使得它的root为d,k的可能取值为1-1000. 第一眼看到这个题,无从下手,想到那么长的数,暴力肯定超时.其实不然,题目要求只要输出任何一个满足条件的即可,因为任何 ...
- 关于python中的特殊方法
研究了几个小时,大概对python中的特殊方法一知半解,现在写写自己的理解,以及记录一些找到的资源.待自己有比较深入理解的时候,再来更新 https://docs.python.org/3/refer ...
- 技巧:结合Zabbix与SNMP监控嵌入式设备
在如何利用Zabbix监控网络设备三篇文章的前两篇中,我们介绍了如何通过Zabbix代理监控网络设备.但有些设备无法安装Zabbix代理,需要采用其他方法监控.需要考虑无法安装软件的嵌入式设备或应用程 ...
- gitee+hexo搭建个人博客
通过gitee和hexo搭建个人博客 首先准备软件: git (提供命令git) git官网 notepad++(方便编辑)notepad++官网 nodejs(hexo依赖)nodejs官网 7z( ...
- 第四次作业;创建raid5,源码编译安装;磁盘配额
创建raid5 格式化 ext4 创建物理卷: 创建卷组: 创建逻辑卷: 格式化 ext4 挂载 开机自启动 创建raid配置文件 源码编译安装: 创建本地yum仓库 umount /dev/sr0 ...
- 从原理层面掌握@RequestAttribute、@SessionAttribute的使用【一起学Spring MVC】
每篇一句 改我们就改得:取其精华,去其糟粕.否则木有意义 前言 如果说知道@SessionAttributes这个注解的人已经很少了,那么不需要统计我就可以确定的说:知道@RequestAttribu ...
- SVG和canvas渲染的性能比较
1.什么是SVG? 描述: 一种使用XML描述的2D图形的语言 SVG基于XML意味着,SVG DOM中的每个元素都是可用的,可以为某个元素附加Javascript事件处理器. 在 SVG 中,每个被 ...
- Postgresql部署及简单操作
PostgreSQL是一个功能强大的开源对象关系数据库管理系统(ORDBMS),在开源数据库使用上与MySQL各领风骚.但也有不少人质疑postgresql的未来,正所谓,赞扬或批判一种数据库都必须先 ...
- java多线程基础(二)--sleep(),wait,()yield()和join()方法
1.sleep()方法 在指定时间内让当前正在执行的线程暂停执行,但不会释放“锁标志”.不推荐使用. sleep()使当前线程进入阻塞状态,在指定时间内不会执行. 2.wait()方法 在其他线程调用 ...