[集合DP] UVA 10651 Pebble Solitaire

根据题目描述,每次变换都减少了一个石子,所以只要求出初始状态最多可以变换多少次,用初始状态石子数目减去这个变换次数就得到最后剩余最少的石子的数目;

最多有12位,用一个 int 表示状态,状态的转移可以用位运算实现。

 1 /*
 2     UVA 10651 - Pebble Solitaire
 3 */
 4 # include <cstdio>
 5 # include <cstring>
 6 
 7 char s[20];
 8 int f[5000];
 9 
10 bool move(int &x, int i, char d)
11 {
12     int t = (x>>(i-2))&0x7;
13     if (d)
14     {
15         if (t == 0x6)
16         {
17             x&=~(1<<i);
18             x&=~(1<<(i-1));
19             x|=1<<(i-2);
20             return true;
21         }
22         return false;
23     }
24     else
25     {
26         if (t == 0x3)
27         {
28             x|=1<<i;
29             x&=~(1<<(i-1));
30             x&=~(1<<(i-2));
31             return true;
32         }
33         return false;
34     }
35 }
36 
37 int max(int x, int y)
38 {
39     return x>y ? x:y;
40 }
41 
42 int dp(int cur)
43 {
44     int &ans = f[cur];
45     if (ans >= 0) return ans;
46     ans = 0;
47     int nst = cur;
48     for (int i = 11; i > 1; --i) if (move(nst, i, 0)) // oo-
49     {
50         ans = max(dp(nst)+1, ans);
51         nst = cur;
52     }
53     nst = cur;
54     for (int i = 11; i > 1; --i) if (move(nst, i, 1)) // -oo
55     {
56         ans = max(dp(nst)+1, ans);
57         nst = cur;
58     }
59 
60     return ans;
61 }
62 
63 int trans(char *s)
64 {
65     int ret = 0;
66     for (int i = 0; i < 12; ++i)
67         if (s[i] == 'o') ret |= 1<<i;
68     return ret;
69 }
70 int count(char *s)
71 {
72     int ret = 0;
73     for (int i = 0; i < 12; ++i)
74         if (s[i] == 'o') ++ret;
75     return ret;
76 }
77 
78 void solve(void)
79 {
80     memset(f, -1, sizeof(f));
81     int tmp = trans(s);
82     int ans = count(s) - dp(tmp);
83     printf("%d\n", ans);
84 }
85 
86 int main()
87 {    
88     int T;
89     scanf("%d", &T);
90     while (T--)
91     {
92         scanf("%s", s);
93         solve();
94     }
95     
96     return 0;
97 }

这算是状态压缩???

转载于:https://www.cnblogs.com/JMDWQ/archive/2012/08/03/2621940.html

Unity Pebble 服务中的广播可以通过以下步骤来实现: 1. 在 Unity 中创建一个新的脚本,例如 BroadcastManager。 2. 在脚本中定义需要广播的消息类型和参数。 3. 使用 Unity 的 SendMessage() 函数来发送消息。 4. 在 Pebble 应用程序中创建一个监听器来接收广播。 5. 在监听器中定义需要执行的操作。 下面是一个示例代码: 在 Unity 中: ``` // BroadcastManager.cs public class BroadcastManager : MonoBehaviour { // Define message type and parameters public enum MessageType { PLAYER_HEALTH_CHANGED, PLAYER_POSITION_CHANGED, PLAYER_SCORE_CHANGED } // Send message using SendMessage() public void SendBroadcastMessage(MessageType messageType, object[] parameters) { SendMessage(messageType.ToString(), parameters); } } ``` 在 Pebble 应用程序中: ``` // AppMessageHandlers.c static void inbox_received_handler(DictionaryIterator *iter, void *context) { Tuple *tuple = dict_read_first(iter); while (tuple) { switch (tuple->key) { case MESSAGE_KEY_BROADCAST_TYPE: if (strcmp(tuple->value->cstring, "PLAYER_HEALTH_CHANGED") == 0) { // Do something when PLAYER_HEALTH_CHANGED message is received } else if (strcmp(tuple->value->cstring, "PLAYER_POSITION_CHANGED") == 0) { // Do something when PLAYER_POSITION_CHANGED message is received } else if (strcmp(tuple->value->cstring, "PLAYER_SCORE_CHANGED") == 0) { // Do something when PLAYER_SCORE_CHANGED message is received } break; } tuple = dict_read_next(iter); } } ``` 在 Pebble 应用程序中注册监听器: ``` // app_init() app_message_register_inbox_received(inbox_received_handler); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); ``` 注意:在发送广播消息时,需要使用字符串表示消息类型,因此需要将 MessageType 转换为字符串。在接收广播消息时,需要比较字符串以确定消息类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值