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 ...
随机推荐
- JPA学习---第五节:日期和枚举等字段类型的JPA映射
1.在上一节可在数据库中看到创建出来的表和字段,是通过 Entity bean 来创建的,而创建表名和字段名的规则是怎样的? 有类,代码如下: package learn.jpa.bean; impo ...
- LoadRunner 学习笔记(1)性能测试常见术语
并发用户数据:与服务器进行交互的在线用户数量 请求响应时间:从Client端发出请求到得到响应的整个时间 一般包括网络响应时间 + server的响应时间 事务请求响应时间:完成这个事务所用的时间 这 ...
- 在云服务器搭建WordPress博客(四)WordPress的基本设置
前面说了 如何安装WordPress,接下来我们需要快速熟悉WordPress,以及进行一些必要的基本设置. 开始设置之前,建议大家先点击一篇左边菜单栏的每一个选项,看看到底是做什么用的.下面开始说一 ...
- bug集合
解决方法:vertical-align:top; 垂直对齐方式:对浮动元素无效浮动类: ie 6 7要在一行显示多个div要 给每一个元素浮动 否则会出间隙. ie6双倍边距bug 1. bug条件 ...
- 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数。
// test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- [转载]AFX_MANAGE_STATE关于资源切换
应用程序进程本身及其调用的每个DLL模块都具有一个全局唯一的HINSTANCE句柄,它们代表了DLL或EXE模块在进程虚拟空间中的起始地址.进程本身的模块句柄一般为0x400000,而DLL模块的缺省 ...
- 项目中libevent几个问题
几个问题: .libevent到底用的是select还是iocp,然后是如何突破64限制的 typedef struct fd_set { u_int fd_count; /* how many ar ...
- SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- N! HDU 1042
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- linux网络配置、环境变量以及JDK安装(CentOS 6.5)
由于需要搭建hadoop平台,但是苦于没有现成可用的linux服务器,只好自己下载了CentOS 6.5从头装起,安装过程中遇到了很多问题,比如网络配置.时钟同步.环境变量配置.以及各种服务的启停,还 ...