Bzoj 1079: [SCOI2008] Coloring scheme (DP)

Source: Internet
Author: User

Dp... Or a memory search ....

Note that 1 <= c_i <= 5, although 1 <= k <= 15, but we can take the remaining paint number the same as the equivalence class

DP (A, B, C, D, E, p) indicates that the paint with paint number 1 is a, and the paint with 2 paints has a B ... p indicates which paint color was used for the last block of wood. Then move on to the code bar ...

--------------------------------------------------------------------

#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#define CLR (x, C) memset (x, C, sizeof (x))#define REP (i, n) for (int i = 0; i < n; ++i)#define MOD (x) ((x)%= MoD)using namespace std;const int MOD = 1e9 + 7;const int MAXN = n; int h[MAXN] [MAXN] [MAXN] [MAXN] [MAXN] [MAXN];int dfs (int a, int b, int c, int d, int e, int p) {int &ans = h[a [b] [C] [d] [E] [P];if (ans) return ans;ans = 0;if (a) mod (ans + = 1LL * (A-(P = = 2)) * DFS (A-1, B, C, D, e, 1)% mod);if (b) mod (ans + + 1LL * (b-(P = = 3)) * DFS (A + 1, b-1, C, D, E, 2)% mod);if (c) mod (ans + + 1LL * (c-(P = = 4)) * DFS (A, B + 1, c-1, D, E, 3)% mod);if (d) mod (ans + = 1LL * (d-(P = = 5)) * DFS (A, B, C + 1, d-1, E, 4)% mod);if (e) mod (ans + = 1LL * E * DFS (A, B, C, D + 1, e-1, 5)% mod);return ans;}int main () {freopen ("test.in", "R", stdin);CLR (h, 0);Rep (i, 6) h[0 [0] [0] [0] [0] [i] = 1;int k, t[6] = {0, 0, 0, 0, 0, 0};cin >> K;While (k--) {int v;scanf ("%d", &v);t[v]++;}cout << dfs (t[1], t[2], t[3], t[4], t[5], 0) << "\ n";return 0;} 

-------------------------------------------------------------------- 

1079: [SCOI2008] Coloring scheme time limit: ten Sec Memory Limit: 162 MB
Submit: 1100 Solved: 697
[Submit] [Status] [Discuss] Description

There are n pieces of wood lined up, numbered from left to right in 1~n. You have a k color of paint, wherein the first color of the paint is enough to tu ci a wood block. All the paint is just enough to fill all the pieces of wood, namely c1+c2+...+ck=n. Adjacent two pieces of wood painted the same color looks very ugly, so you want to count any two adjacent wood color different coloring scheme.

Input

The first behavior is a positive integer k, the second line contains k integers c1, c2, ..., CK.

Output

Outputs an integer, which is the result of modulo 1,000,000,007 for the total number of scenarios.

Sample Input3
1 2 3Sample OutputTenHINT

100% of data meet: 1 <= k <=, 1 <= ci <= 5

Source

Bzoj 1079: [SCOI2008] Coloring scheme (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.