[Fzyzoj 1204] 0 and questions

Source: Internet
Author: User

P1204--0 and questions

Time limit: 1000MS

Memory Limit: 131072KB

Description

Master Chuan, look what you've chosen to tell me how to change the description. ╮ (╯_╰) ╭ Now, please, I can't make up my mind. _ (: 3 J Z) _

Please consider a 1 to N (N=3, 4, 5 ... 9) The number of numbers consists of the increment sequence: 1 2 3 ... N.

Now please insert "+" in the column to indicate plus, or "-" for minus, or "" for whitespace to combine each pair of numbers (do not insert a symbol before the first number).

Calculate the result of the expression and note whether you get the sum as zero.

Please write a program to find out all the resulting and zero length of the sequence of N.

Input Format

A single line represents an integer n (3 <= n <= 9).

Output Format

In the order of ASCII code, output all numbers that can be obtained and zero after inserting "+", "-", or "" between each pair of digits. (Note: You should keep a space even if there are no caret between two numbers)

Sample Input
7
Sample Output
1+2-3+4-5-6+71+2-3-4+5+6-71-2 3+4+5+6+71-2 3-4 5+6 71-2+3+4-5+6-71-2-3-4-5+6+7

Exercises

Water and water search questions, 0S404KB, but hit the table 0s242kb TAT.

1#include <bits/stdc++.h>2 using namespacestd;3 intN;4 Charpos[ A];5 voidprt () {6      for(intI=1; i<n;++i) printf ("%d%c", I,pos[i]);7printf"%d\n", n);8 }9 voidDfsintNowintSumintWintk) {Ten     if(now==n) {if(sum+w*k==0) PRT ();return;} Onepos[now]=' ';d FS (now+1, sum,w*Ten+now+1, k); Apos[now]='+';d FS (now+1, sum+w*k,now+1,1); -pos[now]='-';d FS (now+1, sum+w*k,now+1,-1); - } the intMain () { -scanf"%d",&n); -Dfs1,0,1,1); -     return 0; +}
View Code

To Changzhou, Qaq to start training tomorrow =-= sat for a whole day's bullet train

[Fzyzoj 1204] 0 and questions

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.