Skip to content

Instantly share code, notes, and snippets.

@lili668668
Last active Apr 12, 2016
Embed
What would you like to do?
itsa46測試第三題
import java.math.BigInteger;
import java.util.Scanner;
public class C3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n = input.nextInt();
BigInteger[][] p = new BigInteger[n+1][n+1];
p[1][1] = BigInteger.ONE;
for (int cnt = 2;cnt <= n;cnt++) {
for (int cnt2 = 1;cnt2 <= cnt;cnt2++) {
if (cnt2 == 1 || cnt2 == cnt) {
p[cnt][cnt2] = BigInteger.ONE;
} else {
p[cnt][cnt2] = p[cnt-1][cnt2-1].add(p[cnt-1][cnt2]);
}
}
}
for (int cnt = 1;cnt <= n;cnt++) {
boolean flag = false;
for (int cnt2 = 1;cnt2 <= cnt;cnt2++) {
if (flag) {
System.out.print(" " + p[cnt][cnt2]);
} else {
System.out.print(p[cnt][cnt2]);
flag = true;
}
}
System.out.println();
}
input.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment