usaco

Clean implementations of solutions to USACO problems

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int MOD = 1e9+7;

inline int add(int a, int b) {
	int c = a+b;
	if (c > MOD) c -= MOD;
	return c;
}

int H[105], DP[1005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int N; cin >> N;
	for (int i = 0; i < N; ++i) cin >> H[i];
	int mn = *min_element(H, H+N), mx = *max_element(H, H+N), ans = 0;
	do {
		fill(DP, DP+mx+1, 1);
		for (int i = 0; i < N; ++i) {
			reverse(DP, DP+H[i]+1);
			fill(DP+H[i]+1, DP+mx+1, 0);
			partial_sum(DP, DP+mx+1, DP, add);
		}
		ans = add(DP[0], ans);
		for (int i = 0; i < N; ++i) --H[i];
	} while (N&1 && mn-- && mx--);
	cout << ans;
}