Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

If coin order matters, that is, each sequence is unique, the DP function is simple enough to make it 1D DP. But key is that order DOESN'T matter, so we need to add one more state: ending coin. And for each DP advance step, we only put >= coins.

复制代码
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

typedef unsigned long long ULL;

int main()
{
    unsigned n, m;
    cin >> n >> m;
    vector<ULL> v(m);
    for (unsigned i = 0; i < m; i++)
        cin >> v[i];
    std::sort(v.begin(), v.end());

    //    dp[val][ending coin]
    vector<vector<ULL>> dp(n + 1, vector<ULL>(m, 0));
    dp[0][0] = 1;
    for (unsigned i = 0; i <= n; i++)
    for (unsigned j = 0; j < m; j ++)
    {
        for (unsigned k = j; k < m; k ++)
        {    
            if((ULL(i) + v[k]) <= ULL(n))
                dp[ULL(i) + v[k]][k] += dp[i][j];
        }
    }
    ULL ret = 0;
    for(unsigned i = 0; i < m; i ++)    ret += dp[n][i];
    cout << ret << endl;
    return 0;
}
复制代码
posted on   Tonix  阅读(459)  评论(0编辑  收藏  举报
编辑推荐:
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单
历史上的今天:
2014-06-30 POJ #1221 - NIMODAL PALINDROMIC DECOMPOSITIONS
点击右上角即可分享
微信分享提示