srm 534

250


Description

给你一个1*n的棋盘,两人轮流行动,每个人可以把”o”向右移动到空格子,或者跨越连续两个”o”到空格子。一个”o”到最右端的时候消失。问谁获胜。

Solution

一个比较有趣的题,我们考虑每个”o”到最右端的距离,两种行动其实都是改变距离的奇偶,所以其实只需要考虑最终状态和距离和的奇偶性即可。

Code

#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int d[(1 << N) + 10];
class EllysCheckers {
    public:
    string getWinner(string board) {
        int n = board.size();
        int t = 0;
        for (int i = 0; i < n; ++i) {
            if (board[i] == 'o')    t += n - i - 1;
        }
        return t & 1 ? "YES" : "NO";
    }
};

500



Description:

求把一个 n(n1018) 数分解成几个给定的数组中的几个数的乘积形式的方案数,要求从给定数组中选出的数要两两互质。

Solution

很容易反应到,由于 2×3×...×43>1018 ,所以其实 n <script type="math/tex" id="MathJax-Element-3">n</script>会被分解成不超过15个质数,且每个质数对应的数组中的数只有一个,就可以状压dp了。
也可以直接用map来dp,可以证明,状态数不会太多。

Code:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
int p[20];
const int N = 505;
LL a[N];
vector<int> b;
map<LL, LL> dp;
map<LL, LL>:: iterator it;
class EllysNumbers {
    public:
        long long getSubsets(long long n, vector <string> special) {
            string s = accumulate(special.begin(), special.end(), string());
            istringstream ss(s);
            int m = 0, x;
            while (ss >> x) a[m++] = x;
            for (int i = 0; i < m; ++i)
                if (__gcd(a[i], n / a[i]) == 1) b.pb(a[i]);
            dp[n] = 1;
            for (int i = 0; i < b.size(); ++i)
                for (it = dp.begin(); it != dp.end(); it++)
                    if (it -> F % b[i] == 0) {
                        dp[it -> F / b[i]] += it -> S;
                    }
            return dp[1];
        }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值