写了一记忆化 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的更多相关文章

  1. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  2. 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 ...

  3. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  4. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  5. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  6. Codeforces Round #204 (Div. 2) A.Jeff and Digits

    因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #204 (Div. 2): B

    很简单的一个题: 只需要将他们排一下序,然后判断一下就可以了! 代码: #include<cstdio> #include<algorithm> #define maxn 10 ...

随机推荐

  1. JAVA类与对象(三)----类定义关键字详解

    static 表示静态,它可以修饰属性,方法和代码块. 1.static修饰属性(类变量),那么这个属性就可以用类名.属性名来访问,也就是使这个属性成为本类的类变量,为本类对象所共有.这个属性就是全类 ...

  2. C++中的快速排序(使用vector和数组的不同)

    1.快速排序是最最基本的排序算法之一,时间复杂度是O(nlog2(n)) 基本思想:分治法+递归 假设key为该序列的第一个元素,从后往前遍历,找到第一个小于key值的元素,将该元素赋值给左边的起始值 ...

  3. Version of SQLite used in Android?

    sing the emulators (adb shell sqlite3 --version): SQLite 3.7.11: 19-4.4-KitKat 18-4.3-Jelly Bean 17- ...

  4. 适配iOS10以及Xcode8-b

    现在在苹果的官网上,我们已经可以下载到Xcode8的GM版本了,加上9.14日凌晨,苹果就要正式推出iOS10系统的推送了,在此之际,iOS10的适配已经迫在眉睫啦,不知道Xcode8 beat版本, ...

  5. bnuoj 25662 A Famous Grid (构图+BFS)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...

  6. android 开发 获取各种intent (图片、apk文件、excel、pdf等文件)

    public static Intent openFile(String filePath){ File file = new File(filePath); if(!file.exists()) r ...

  7. web.xml中servlet的配置

    <servlet>元素是配置Servlet所用的元素. <servlet-mapping>元素在Servlet和URL样式之间定义一个映射,即servlet类提供一个url,在 ...

  8. 【贪心】Bzoj 2457:[BeiJing2011]双端队列

    2457: [BeiJing2011]双端队列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 209  Solved: 95[Submit][Stat ...

  9. 【转载】C++中结构体的声明和定义

    http://blog.csdn.net/whuslei/article/details/5665289 1  //定义一个结构体,类型为struct Student 2  struct  Stude ...

  10. Guava文档翻译之 Guava简介

    用户指南 User Guide Guava项目包括了一些Google的核心库,是我们在基于Java的项目中所依赖的,这些库包括:集合,缓存,对基本类型的支持,并发库,通用的注解,字符串处理,I/O,等 ...