2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description
Nike likes playing cards and makes a problem of it.
Now give you n integers, ai(1≤i≤n)
We define two identical numbers (eg: 2,2) a Duizi,
and three consecutive positive integers (eg: 2,3,4) a Shunzi.
Now you want to use these integers to form Shunzi and Duizi as many as possible.
Let s be the total number of the Shunzi and the Duizi you formed.
Try to calculate max(s).
Each number can be used only once.
Input
The input contains several test cases.
For each test case, the first line contains one integer n(1≤n≤106).
Then the next line contains n space-separated integers ai (1≤ai≤n)
Output
For each test case, output the answer in a line.
Sample Input
7
1 2 3 4 5 6 7
9
1 1 1 2 2 2 3 3 3
6
2 2 3 3 3 3
6
1 2 3 3 4 5
Sample Output
2
4
3
2
Hint
Case 1(1,2,3)(4,5,6)
Case 2(1,2,3)(1,1)(2,2)(3,3)
Case 3(2,2)(3,3)(3,3)
Case 4(1,2,3)(3,4,5)
題目大意:有兩種操作:可以用三張連續(xù)的牌組成順子,可以用兩張相同的牌組成對子,記對子和順子的和為S,求Max(s)
解題報告:這題考場沒寫出來,第一步很容易想到,那就是把多出來的對子先打掉,這樣顯然更優(yōu)(雖然此時可以組成順子,但是組成對子是等價的,不會影響答案),現(xiàn)在每一張牌就只剩下1或2張了,考慮剩下的牌怎么打..
然后我就掛在了這里,天真的以為直接能打順子就打掉,打完即可,然后掛在了手make的1 1 2 3 3 這組上,此時考試已經(jīng)結(jié)束了..考后發(fā)現(xiàn)這里是需要DP的,對于剩一張牌的我們不需要決策,能用到就用到.剩兩張牌需要做決策,顯然是可以選擇打一個對子或兩個順子,顯然兩個順子是更好的,所以能打兩個順子就打掉,不能就打?qū)ψ?
轉(zhuǎn)載于:https://www.cnblogs.com/Yuzao/p/7460107.html
總結(jié)
以上是生活随笔為你收集整理的2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 10分钟开始.Net Core
- 下一篇: python的引用计数分析(二)