Hackerrank Equal(这特么也是dp???)
2017-08-28 20:15
435 查看
咸鱼的等待着军训,哎呀真的很烦,没有事情可做.
随便玩玩咯.
印度人很恶心,喜欢各种trick.
随便玩玩咯.
印度人很恶心,喜欢各种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; }
相关文章推荐
- Hackrank Equal DP
- 【HackerRank】Fair Cut(DP)
- HackerRank: Equal
- HackerRank Even Tree(树dp)
- HackerRank "Equal Stacks"
- HackerRank - lucky-numbers(数位DP)
- HackerRank - common-child【DP】
- hackerrank The Coin Change Problem(dp)
- HackerRank - "Fraud Prevention"
- C++ HackerRank|Waiter
- hackerrank Roads and Libraries(DFS/并查集)
- HackerRank - organizing-containers-of-balls
- 最少拦截系统,简单dp,(学长说这是贪心?!。。。。。。也是醉了)
- [HackerRank]Choosing White Balls
- 【Hacker Rank】04.Arithmetic Operators
- Hackrank Candies DP
- hackerrank DFS Edges
- HackerRank - Common Child
- [线段树][单调栈]HackerRank 101 Hack 50 .Boxes for Toys
- HackerRank难题记录