USACO Section 3.3: Home on the Range

到最后发现是DP题

 1 /*

 2 ID: yingzho1

 3 LANG: C++

 4 TASK: range

 5 */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <stdio.h>

14 #include <queue>

15 #include <cstring>

16 #include <cmath>

17 #include <list>

18 #include <cstdio>

19 #include <cstdlib>

20 #include <limits>

21 #include <stack>

22 

23 using namespace std;

24 

25 ifstream fin("range.in");

26 ofstream fout("range.out");

27 

28 int N;

29 

30 int main()

31 {

32     fin >> N;

33     vector<string> input(N);

34     for (int i = 0; i < N; i++) {

35         fin >> input[i];

36     }

37     vector<vector<int> > range(N, vector<int>(N));

38     for (int i = 0; i < N; i++) {

39         for (int j = 0; j < N; j++) {

40             range[i][j] = input[i][j] - '0';

41         }

42     }

43     vector<int> num(N+1);

44     for (int i = N-2; i >= 0; i--) {

45         for (int j = N-2; j >= 0; j--) {

46             if (range[i][j]) range[i][j] = min(range[i+1][j], min(range[i][j+1], range[i+1][j+1]))+1;

47             if (range[i][j] > 1)

48                 for (int k = 2; k <= range[i][j]; k++) num[k]++;

49         }

50     }

51     for (int i = 2; i <= N; i++) {

52         if (num[i]) fout << i << " " << num[i] << endl;

53     }

54 

55     return 0;

56 }

 

你可能感兴趣的:(USACO)