Codeforces Round #204 (Div. 2) C
写了一记忆化 TLE了 把double换成long long就过了 double 这么耗时间啊
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 4010
#define INF 0xfffffff
#define LL long long
double a[N];
LL dp[N][N],b[N][];
int n;
LL dfs(int i,int r1,int r2,LL ss)
{
if(i>*n)
return dp[r1][r2] = ;
if(r1<=&&r2<=)
return ;
if(dp[r1][r2]!=INF)
return dp[r1][r2];
LL bs = ss,as = ss,s1,s2;
if(r1)
{
s1 = (b[i][]+dfs(i+,r1-,r2,ss+b[i][]));
as += (b[i][]+dfs(i+,r1-,r2,ss+b[i][]));
}
if(r2)
{
s2 = b[i][]+dfs(i+,r1,r2-,ss+b[i][]);
bs+=b[i][]+dfs(i+,r1,r2-,ss+b[i][]);
}
if(r1&&r2)
{
if(abs(bs)<abs(as))
return dp[r1][r2] =s2 ;
else
return dp[r1][r2] = s1;
}
else if(r1)
return dp[r1][r2] = s1;
else
return dp[r1][r2] = s2;
}
int main()
{
int i,j;
scanf("%d",&n);
for(i = ; i <= *n ; i++)
for(j = ; j <= *n ; j++)
dp[i][j] = INF;
for(i = ; i <= *n ; i++)
{
scanf("%lf",&a[i]);
b[i][] = (floor(a[i])-a[i])*;
b[i][] = (ceil(a[i])-a[i])*;
}
/*for(i = 2*n-1 ;i >=1 ; i--)
for(j = 2*n; j >= 1 ; j--)
{
double
}*/
LL s = dfs(,n,n,);
printf("%.3lf\n",(double)fabs(s)/10000000.0);
return ;
}
Codeforces Round #204 (Div. 2) C的更多相关文章
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- Codeforces Round #204 (Div. 2)->C. Jeff and Rounding
C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- Codeforces Round #204 (Div. 2) A.Jeff and Digits
因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...
- Codeforces Round #204 (Div. 2)->D. Jeff and Furik
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #204 (Div. 2)->B. Jeff and Periods
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #204 (Div. 2): B
很简单的一个题: 只需要将他们排一下序,然后判断一下就可以了! 代码: #include<cstdio> #include<algorithm> #define maxn 10 ...
随机推荐
- LintCode-Median II
Numbers keep coming, return the median of numbers at every time a new number added. Example For numb ...
- easyui页面布局
html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- SQLServer2005:在执行批处理时出现错误。错误消息为: 目录名无效
删除数据时忘了想delete删除的话会记录日志,更何况是我删除百万条数据,结果还没删完服务器内存就占慢了,一切数据都进不来了,估计这种情况导致我的数据库有问题了,右键打开表提示:目录名无效,执行SQL ...
- WPF解析PPT为图片
偶遇需要解析 PPT为单张图片 其中,对于包含动画的PPT页,分别对动画最后效果进行截取,即每个连续动画截取 (动画N个)N+1(原图)张 http://git.oschina.net/jiailiu ...
- 公众号开发学习Day01
登录https://mp.weixin.qq.com/后点击注册进入注册微信公众号界面,使用邮箱进行注册 注意点1:一个邮箱只能创建一个公众号,并且公众号的三种类型(订阅号,服务号,企业号)只能选一种 ...
- maven学习心得整理
maven的学习心得 已经接触了maven项目有一段时间了,开始时仅仅会使用,在使用中发现了它的强大和方便,于是决心研究一下: 首先,普及一下maven参数: -D:传入属性参数 -P:使用POM中指 ...
- 文本编辑器 markdown
http://www.cnblogs.com/youxia/p/linux014.html markdown对数学公式的支持http://www.linuxidc.com/Linux/2014-08/ ...
- 【HDOJ】【1512】Monkey King
数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...
- BestCoder Round #3
Task schedule http://acm.hdu.edu.cn/showproblem.php?pid=4907 #include<cstdio> #include<cstr ...
- [设计模式] 10 外观模式 facade
外观模式应该是用的很多的一种模式,特别是当一个系统很复杂时,系统提供给客户的是一个简单的对外接口,而把里面复杂的结构都封装了起来.客户只需使用这些简单接口就能使用这个系统,而不需要关注内部复杂的结构. ...