动态规划 一层循环

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader();
		PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] dp = new int[n + 1];//第i层之前有多少个数
        dp[1] = 1;
        for(int i = 2; i <= n; ++i)
            dp[i] = dp[i - 1] + i;
        for(int i = 1, j = 1; j <= n; ++i) {
            out.printf("%4d", i);
            if(i == dp[j]) {out.println();++j;}//换行时机
        }
		out.close();
	}
}
class InputReader{BufferedReader buf;StringTokenizer tok;InputReader(){buf = new BufferedReader(new InputStreamReader(System.in));}boolean hasNext(){while (tok == null || !tok.hasMoreElements()){try{tok = new StringTokenizer(buf.readLine());}catch (Exception e){return false;}}return true;}String next(){if (hasNext())
			return tok.nextToken();return null;}int nextInt(){return Integer.parseInt(next());}long nextLong(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}BigInteger nextBigInteger(){return new BigInteger(next());}BigDecimal nextBigDecimal(){return new BigDecimal(next());}}