zoukankan      html  css  js  c++  java
  • 【LG5020】[NOIP2018]货币系统

    【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
    ", ans); 
    	} 
    	return 0; 
    } 
    
  • 相关阅读:
    访问 IIS 元数据库失败
    C# List<T>运用
    Unicode 数据
    讲解SQL Server 2000的Collection排序规则
    delphi Format用法
    delphi 文件的操作
    class of 语句
    深入delphi编程
    delphi 事件委托 未看
    如何让delphi在启动时不自动创建空的工程?
  • 原文地址:https://www.cnblogs.com/heyujun/p/9979286.html
Copyright © 2011-2022 走看看