1. 程式人生 > >hdu 1709(普通型母函式)

hdu 1709(普通型母函式)

The Balance

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3249    Accepted Submission(s): 1294


Problem Description Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality of all the weights.

Input The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality of each weight where 1<=Ai<=100.

Output For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.

Sample Input 3 1 2 4 3 9 2 1
Sample Output 0 2 4 5
Source
Recommend lcy 題目型別:普通型母函式 題目描述:給你n個砝碼,一個天平,砝碼總共重s.問在[1,s]的這個區間裡,哪個重量稱不出來。 題目分析:因為天平左右都能放砝碼,所以可以這樣。往左面放認為是正,往右面放認為是負。這樣每個砝碼的母函式相當於 x^-v[i] 1 x ^ v[i]. 程式碼如下:
#include <stdio.h>
#include <memory.h>
#define N 10001
#define M 101

int r[N];
int fr[N];
int t[N];
int ft[N];
int v[M];
int n,s;

int jd(int x){
    if(x < 0){
        x = -x;
    }
    return x;
}

void init(){
    int i,j,k;
    memset(r,0,sizeof(r));
    memset(fr,0,sizeof(fr));
    memset(t,0,sizeof(t));
    memset(ft,0,sizeof(ft));
    r[0] = 1,r[v[0]] = 1,fr[v[0]] = 1;

    for( k = 1; k < n; k++){
        for( i = 0; i <= s; i++){
            for( j = -v[k]; j <= v[k]; j += v[k]) {
                if( r[i] != 0) {
                    if(i+j < 0){
                        ft[jd(i+j)] = 1;
                    } else {
                        t[i+j] = 1;
                    }
                }
            }
        }
        for( i = 1; i <= s; i++){
            for( j = -v[k]; j <= v[k]; j += v[k]) {
                if( fr[i] != 0){
                    if( -i + j < 0){
                        ft[jd(-i+j)] = 1;
                    } else {
                        t[-i+j] = 1;
                    }
                }
            }
        }

        for( i = 0; i <= s ;i++){
            r[i] = t[i];
            t[i] = 0;
            fr[i] = ft[i];
            ft[i] = 0;
        }
    }
}
void result(){
    int i,sum = 0;
    for( i = 0; i <= s; i++){
        if(r[i] == 0){
            sum++;
        }
    }
    printf("%d\n",sum);
    if( sum != 0) {
        int flag = 0;
        for( i = 0; i <= s; i++){
            if(r[i] == 0) {
                if( flag == 0){
                    flag = 1;
                } else {
                    printf(" ");
                }
                printf("%d",i);
            }
        }
        printf("\n");
    }
}


int main()
{
    while(scanf("%d",&n) != EOF){
        s = 0;
        int i;
        for( i = 0; i < n; i++){
            scanf("%d",v+i);
            s += v[i];
        }
        init();
        result();
    }

    return 0;
}


相關推薦

hdu 1709(普通型函式)

The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3249    Accepted Su

hdu 1028(普通型函式)

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6

B.找單詞——(HDU 2082 普通型函式

傳送門 找單詞 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S

hdu 1171(普通型函式)

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11501    Acce

hdu 1709函式,有些特殊)

母函式。。 #include"stdio.h" #include"string.h" int main() { int a[10008]; int b[10008]; in

HDU 1709函式

The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot

hdu 2082--找單詞 普通型函式的應用

B - 找單詞 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De

HDU 2082 普通型函數

ace () -1 分析 show pac include 分享 amp 分析: 組成單詞好說,價值如何體現? 改變指數就行,例如: 這樣,組成的單詞,指數就是權值,多項式相乘,指數小於50的就OK; 1 #include <b

2017多校訓練賽第一場 HDU 6042 (函式

Journey with Knapsack Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 164    A

普通型函式原理及模板程式碼詳解

母函式有很多種,最常用的有普通型母函式和指數型母函式。兩者區別是:普通型母函式主要是來求組合的方案數,而指數型母函式是求多重排列數。下面只講解普通型母函式的相關知識。定義:若函式G(x)=a0+a1*x

普通型函式

生成函式(母函式)有普通生成函式和指數生成函式: 1.普通生成函式用於解決多重集的組合問題 2.指數型母函式用於解決多重集的排列問題 母函式可以解決遞迴數列的通項問題:斐波那契數列、卡特蘭數列等 普通母函式:     構造母函式G(x), G(x) = a0 + a

普通型函式和指數型函式

母函式:摘自百度百科 生成函式即母函式,是組合數學中尤其是計數方面的一個重要理論和工具。生成函式有普通型生成函式和指數型生成函式兩種,其中普通型用的比較多。形式上說,普通型生成函式用於解決多重集的組合問題,而指數型母函式用於解決多重集的排列問題。母函式還可以解決遞迴數列的通

HDU 2152(函式

Problem Description 轉眼到了收穫的季節,由於有TT的專業指導,Lele獲得了大豐收。特別是水果,Lele一共種了N種水果,有蘋果,梨子,香蕉,西瓜……不但味道好吃,樣子更是好看。 於是,很多人們慕名而來,找Lele買水果。 甚至連大名鼎鼎的HDU ACM

hdu 2082(普通函式)

/*     hdu 2082     普通母函式     直接套模板就行     普通母函式主要解決組合問題     大概思路是開2個數組,c1[ ]儲存當前得到的多項式各項係數,c2[ ]儲存每次計算時的臨時結果,     (解釋下c1[a]=b,其中a為多項式中x的指

HDU 1028 (函式或者dp)

“The second problem is, given an positive integer N, we define an equation like this: N=a[1]+a[2]+a[3]+…+a[m]; a[i]>0,1<

hdu 1709 函式

The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7220    Accepted S

組合數學-普通型生成函式(函式)-hdu2082 找單詞

 Problem Description 假設有x1個字母A, x2個字母B,..... x26個字母Z,同時假設字母A的價值為1,字母B的價值為2,..... 字母Z的價值為26。那麼,對於給定的字母,可以找到多少價值<=50的單詞呢?單詞的價值就是組成一個單詞的所有字母的價值之和,比

hdu 1521 排列組合【指數型函式

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1521   指數型母函式定義及其作用: #include<stdio.h> #include<string.h> #include<string&

hdu 1171 Big Event in HDU函式

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1171 題意:航電計算機學院要分成軟體學院和計算機學院,要分物資,計算機學院的物資不少於比軟體學院的(儘可能平均的請款下) 思路:母函式做一發,基本套模板,記錄一下數量和價值還有總價值即可 #

排列組合 HDU - 1521 -指數型函式

排列組合  HDU - 1521  一句話區分指數型母函式和母函式就是 母函式是組合數,指數型母函式是排列數 #include<bits/stdc++.h> using namespace std; #define maxn 12 dou