HDU 1133 Buy the Ticket 卡特蘭數,hdu1133

來源:互聯網
上載者:User

HDU 1133 Buy the Ticket 卡特蘭數,hdu1133

設50元的人為+1 100元的人為-1 滿足前任意k個人的和大於等於0 卡特蘭數

C(n+m, m)-C(n+m, m+1)*n!*m!

import java.math.*;import java.util.*;public class Main {    /**     * @param args     */    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int cas = 1;        while(true){            int m = sc.nextInt();            int n = sc.nextInt();            if(m == 0 && n == 0)                break;            System.out.println("Test #"+cas+":");            cas++;            if(m < n){                System.out.println(0);                continue;            }            BigInteger ans1 = BigInteger.valueOf(1);            int x = n+m;            for(int i = 1; i <= m; i++){                ans1 = ans1.multiply(BigInteger.valueOf(x));                x--;            }            for(int i = 1; i <= n; i++){                ans1 = ans1.multiply(BigInteger.valueOf(i));            }            BigInteger ans2 = BigInteger.valueOf(1);            x = n+m;            for(int i = 1; i <= m+1; i++){                ans2 = ans2.multiply(BigInteger.valueOf(x));                x--;                ans2 = ans2.divide(BigInteger.valueOf(i));            }            for(int i = 1; i <= n; i++){                ans2 = ans2.multiply(BigInteger.valueOf(i));            }            for(int i = 1; i <= m; i++){                ans2 = ans2.multiply(BigInteger.valueOf(i));            }                        System.out.println(ans1.subtract(ans2));        }    }}



杭電acm 1133 Buy the Ticket找錯

# include <stdio.h> # include <string.h> # include <math.h> # include <stdlib.h> int main(int argc, char *argv[]){int n,m,a,b,c,max,t=0;while(scanf("%d%d",&m,&n)!=EOF){if(m==0&&n==0) break;int sh[100]={1};max=0;for(a=1;a<=m+n;a++){if(a!=m+1)for(b=0;b<=max;b+){//應該是for(b=0;b<=max;b++){sh[b]*=a;if(sh[b]>10000){if(b+1>max)max++;sh[b+1]=sh[b]/10000;sh[b]=sh[b]%10000;}}}printf("Test #%d:\n",++t)//這 少個分號 (要學會看下面的編譯資訊啊)for(a=max;a>=0;a--){if(a==max) printf("%d",sh[a]);else printf("%5d",sh[a]);}printf("\n");}return 0;}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.