首页 > 其他 > 详细

【LG5020】[NOIP2018]货币系统

时间:2018-11-18 21:00:33      阅读:307      评论:0      收藏:0      [点我收藏+]

【LG5020】[NOIP2018]货币系统

题面

洛谷

题解

考场上第一眼还不会233
可以发现只要可以被其他的货币通过一些奇奇怪怪的方式表示出来的货币就\(ban\)掉即可
就是个完全背包
我是统计的方案数,用\(unsigned\) \(long\) \(long\)防炸\(int\)
就算炸掉了无符号长整型也可能对

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits> 
using namespace std;
inline int gi() {
    register int data = 0, w = 1;
    register char ch = 0;
    while (ch != '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (isdigit(ch)) data = data * 10 + ch - '0', ch = getchar();
    return w * data; 
}
#define MAX_N 105
#define MAX_V 25005 
int N, a[MAX_N]; 
unsigned long long dp[MAX_V];
#define RG register 
void solve() {
    dp[0] = 1; 
    for (RG int i = 1; i <= N; i++) {
        for (RG int j = a[i]; j <= a[N]; j++) dp[j] += dp[j - a[i]]; 
    } 
} 
int main () {
    int T = gi();
    while (T--) {
        N = gi(); for (int i = 1; i <= N; i++) a[i] = gi();
        sort(&a[1], &a[N + 1]);
        N = unique(&a[1], &a[N + 1]) - a - 1; 
        memset(dp, 0, sizeof(dp));
        solve(); 
        int ans = N; 
        for (int i = 1; i <= N; i++) if (dp[a[i]] > 1) ans--;
        printf("%d\n", ans); 
    } 
    return 0; 
} 

【LG5020】[NOIP2018]货币系统

原文:https://www.cnblogs.com/heyujun/p/9979286.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!