URAL 1260 Nudnik photographer DFS DP

Source: Internet
Author: User

Title: Click here

: This problem can first DFS deep search, regular DP

Dfs:

1#include <bits/stdc++.h>2 using namespacestd;3 #defineS Second4typedefLong Longll;5 Const intINF =0x3f3f3f3f;6 Const intM = 1e5+3;7 8 ints;9 intCNT =0;Ten BOOLvis[ -]; One voidDfsintLastintnum) { A     if(num = =s) { -cnt++; -         return ; the     } -      for(intI=2; i<s+1; i++ ) -         if(ABS (LAST-I) <=2&&!Vis[i]) { -Vis[i] =true; +DFS (i, num+1 ); -Vis[i] =false; +         } A } at intMain () { -      while(~SCANF ("%d", &s)) { -memset (Vis,false,sizeof(Vis)); -CNT =0; -vis[1] =true; -Dfs1,1 ); inprintf"%d\n", CNT); -     } to     return 0; +}
View Code

Dp:

1#include <bits/stdc++.h>2 using namespacestd;3 #defineF First4 #defineS Second5typedef unsignedLong Longll;6 Const intINF =0x3f3f3f3f;7 Const intM = 1e5+3;8 9 ints;Tenll dp[ -]; One voidPre () { AMemset (DP,0,sizeof(DP)); -dp[1] =1; -dp[2] =1; thedp[3] =2; -dp[4] =4; -      for(intI=5; i<= -; i++ )    -Dp[i] = dp[i-1]+dp[i-3]+1; + } - intMain () { + pre (); A      while(~SCANF ("%d", &s)) { atprintf"%i64d\n", Dp[s]); -     } -     return 0; -}

URAL 1260 Nudnik photographer DFS 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.