写了一记忆化 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. Css compatibility

    http://meiert.com/en/indices/css-properties/ http://www.standardista.com/css3/css3-selector-browser- ...

  2. 微信消息处理JAXP-sax解析

    package cn.zhaokai.sax; import java.io.IOException; import java.io.InputStream; import java.io.Print ...

  3. SSMS 2008R2没有智能感知方法解决

    有时SSMS会莫明奇妙的没有了智能感知(前一天还是有的, 第2天就没有了) 在网上查到有如下原因: 1. 服务器上有Offline的DB 解决方案: 将Offline的DB删掉或者设成online即可 ...

  4. IDENTITY属性使用

    转自:http://www.cnblogs.com/seusoftware/p/3804333.html 一. 获取IDENTITY列值插入了数据,有时还需要获取刚才生成的序列值另作他用,返回给前端也 ...

  5. 《剑指Offer》- 面试题3

    <剑指Offer——名企面试官精讲典型编程题>  面试题3:  二维数组元素从左到右.从上到下递增,输入一个二维数组和一个整数,  查找该整数. 自己的思路:有序条件下进行查找,当然最简单 ...

  6. VC6.0环境安装STLport-5.2.1

    今天安装STLport,网上搜资料安装好久,都不行,因为STLport 的版本不对,我这是STLport-5.2.1新版本. (注意:下面的步骤都在一个cmd里操作,很简单的原因:环境变量啊) 1.首 ...

  7. CentOS(RHEL) 操作备忘

    1.安装中文语言包及切换 yum groupinstall chinese-support vi /etc/sysconfig/i18n change en_US to zh_CN 2.用户自动登录 ...

  8. 为什么android的R类要定义成16进制

    联想到c语言中的宏定义:我想是一个原因 如: #define SDL_INIT_TIMER 0x00000001 #define SDL_INIT_AUDIO 0x00000010 #define S ...

  9. C# Socket编程笔记(转)

    C# Socket编程笔记 http://www.cnblogs.com/stg609/archive/2008/11/15/1333889.html TCP Socket:Server 端连接步骤: ...

  10. Winform基础 -- 菜单

    快速创建默认菜单 使用控件 MenuStrip : 点击菜单的右上方小三角:选择 [插入标准项] 即可显现出标准的菜单格式: 如果想添加更多的菜单项,可以在   [请在此处键入] 处输入菜单项的名称 ...