您的位置:首页 > 其它

Hackerrank Equal(这特么也是dp???)

2017-08-28 20:15 435 查看
咸鱼的等待着军训,哎呀真的很烦,没有事情可做.

随便玩玩咯.

印度人很恶心,喜欢各种trick.

/*  xzppp  */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
const int MAXN = 10000+17;
const int MAXM = 20;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
LL a[MAXN],dp[1000+17];
int main()
{
#ifndef ONLINE_JUDGE
FFF
#endif
int t;
cin>>t;
while(t--)
{
memset(dp, 0, sizeof(dp));
LL n,mn=INF;
cin>>n;
for (int i = 0; i < n; ++i)
{
scanf("%lld",a+i);
mn = min(a[i],mn);
}
LL h[10] = {0};
for (int i = 0; i < n; ++i)
{
a[i]-=mn;
int temp = a[i]/5;
h[5]+=temp;
a[i]-=temp*5;
h[a[i]]++;
}
dp[mn] = h[1]+h[2]+2*h[3]+2*h[4]+h[5];
LL ans = min(dp[mn],1LL*INF);
LL have = h[5];
for (int i = mn-1; i > mn-10; --i)
{
have += h[4];
int temp = h[0];
h[0] = h[4];
h[4] = h[3];
h[3] = h[2];
h[2] = h[1];
h[1] = temp;
LL zz = (h[1]+h[2]+2*h[3]+2*h[4])+have;
ans = min(ans,zz);
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm