CodeforcesRound #247 (Div.2) ABC

Source: Internet
Author: User
CodeforcesRound #247 (Div.2) codeforces. comcontest431 code has been released: github. comgatezwaytoacmtreemastercodeforces431a

Codeforces role #247 (Div. 2) http://codeforces.com/contest/431 code has been put on: https://github.com/illuz/WayToACM/tree/master/CodeForces/431 A-Black Square question address: Jury play don't step on the white block, the game has four areas, Jury points each area to consume ai calories

Codeforces Round #247 (Div. 2)

Http://codeforces.com/contest/431
Code is delivered: https://github.com/illuz/WayToACM/tree/master/CodeForces/431

A-Black Square

Question address

Question:
Do not step on the white block for Jury. There are four areas in the game. Jury points consume ai calories in each area, and the sequence of stepping on the white block is displayed, asking how many calories are consumed.

Analysis:
Simulate questions ..

Code:

/**  Author:      illuz 
 
  *  File:        a.cpp*  Create Date: 2014-05-21 23:33:25*  Descripton:   */#include 
  
   #include 
   
    #include 
    
     using namespace std;int a[5], ans;string s;int main(){for (int i = 1; i <= 4; i++)cin >> a[i];cin >> s;for (int i = 0; i < s.length(); i++)ans += a[s[i] - '0'];cout << ans << endl;return 0;}
    
   
  
 


B-Shower Line

Question address

Question:
Five students are waiting in queue. In each situation, the 2i-1 and 2nd students talk in queue. During a conversation, conversations between individuals I and j will generate the values of g [I] [j] + g [j] [I] Joy (fun, calculates the greatest value of joy.

Analysis:
At the beginning, I thought the number of people was not fixed. I hesitated for a while...
Directly use next_permutation for violence, 5! Is acceptable.

Code:

/**  Author:      illuz 
 
  *  File:        b.cpp*  Create Date: 2014-05-21 23:43:23*  Descripton:   */#include 
  
   #include 
   
    #include using namespace std;const int N = 5;char ch;int g[N][N], mmax;int a[5] = {0, 1, 2, 3, 4};int main(){int i = 0, j = 0;for (int i = 0; i < 5; i++)for (int j = 0; j < 5; j++)scanf("%d", &g[i][j]);for (int i = 0; i < 5; i++)for (int j = i + 1; j < 5; j++) {g[j][i] = g[i][j] = g[i][j] + g[j][i];}do {mmax = max(mmax, g[a[0]][a[1]] + g[a[1]][a[2]] + g[a[2]][a[3]] * 2 + g[a[3]][a[4]] * 2);} while (next_permutation(a, a + 5));cout << mmax << endl;return 0;}
   
  
 


C-k-Tree

Question address

Question:
An infinite k-tree is defined as follows:
Each node has k branches, and the edge value of the I branch is I.
Ask how many paths are in the k-tree, where at least one edge weight is not less than d, and the path edge is n.

Analysis:
The game was not knocked out (too weak orz). After the game, I found something wrong...
This problem can be solved by using dp. Because it is an infinite tree, the root node is the same as each node, but it also requires a factor to shift to a sub-problem, that is, the Condition Limiting edge must be <= d. Therefore, we can enable one-dimensional storage to determine whether the Condition Limiting is required.
For details, see the code...

Code:

/**  Author:      illuz 
 
  *  File:        c.cpp*  Create Date: 2014-05-22 00:20:28*  Descripton:   */#include 
  
   #include 
   
    #include 
    
     using namespace std;typedef long long ll;const int N = 110;const int MOD = 1e9 + 7;ll D[N][2];int n, d, k;ll dp(int r, bool b){if (D[r][b] != -1)return D[r][b];if (r == 0)return D[r][b] = b;D[r][b] = 0;for (int i = 1; i <= min(r, k); i++)if (b || i >= d)D[r][b] = (D[r][b] + dp(r - i, 1)) % MOD;elseD[r][b] = (D[r][b] + dp(r - i, 0)) % MOD;return D[r][b];}int main(){memset(D, -1, sizeof(D));scanf("%d%d%d", &n, &k, &d);cout << dp(n, 0) << endl;return 0;}
    
   
  
 

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.