HDU 4958 DP

来源:互联网 发布:国外网络流行模式 编辑:程序博客网 时间:2024/06/06 00:38
////  main.cpp//  HDU 4958 DP////  Created by 郑喆君 on 8/18/14.//  Copyright (c) 2014 itcast. All rights reserved.//#include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <fstream>#include <numeric>#include <iomanip>#include <bitset>#include <list>#include <stdexcept>#include <functional>#include <utility>#include <ctime>#include <cassert>#include <complex>using namespace std;typedef long long ll;typedef long double ld;const int int_max = 0x07777777;const int int_min = 0x80000000;const int inf=0x20202020;const ll mod=1000000007;const double eps=1e-9;const double pi=3.1415926535897932384626;const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}bool cmp (const void *a , const void *b ){    return *(int *)a < *(int *)b;}ld dp[1005][1005];ld fn (int a, int b) {if(a<0||b<0) return 0; else return dp[a][b];}int main(int argc, const char * argv[]){    dp[0][0] = 0;    for(int i = 0; i < 1005; i++){        for(int j = 0; j < 1005-i; j++){            if(i||j){                if(i%2==0){                    dp[i][j] = i+j+fn(i-1,j)*i/(i+j) + fn(i,j-1)*j/(i+j);                }else{                    dp[i][j] = max(fn(i-1,j),fn(i, j-1));                }            }        }    }    int t;    while (scanf("%d", &t)!=EOF) {        while (t--) {            int n;            scanf("%d", &n);            int cnt = 0;            for(int i = 0; i < n; i++){                int xx;                scanf("%d", &xx);                if(xx%2==1) cnt++;            }            printf("%0.f\n", (double)(dp[cnt][n-cnt]*3));        }    }}

0 0
原创粉丝点击