Codeforces Round #612 (Div. 2) C. Garland题解

题目:

Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.

在这里插入图片描述
Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by 222). For example, the complexity of 1 4 2 3 5 is 2 and the complexity of ​1 3 5 7 6 4 2​ is 111.

No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.

题意:
n个数字(1-n)随意排列,将剩下未使用过的的数字填入空置的位置(以0表示),使得复杂性最小。
复杂性:相邻两数奇偶性不同时,复杂性+1

/**
原问题:最后一位填奇/偶时,奇偶对个数最少
子问题:前一个位置为奇/偶
边界:位置为0时,直接得出解-0

dp[当前位置(长度)][已用偶数个数][当前数奇偶性]
递推: 
对于当前数
填偶数 -- dp[i][j][0] = min(dp[i-1][j-1][0], dp[i-1][j-1][1] + 1); 
填奇数 -- dp[i][j][1] = min(dp[i-1][j][0] + 1, dp[i-1][j][1]);
*/

#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<b; ++i)
using namespace std;
typedef long l
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值