Last active
September 12, 2015 17:27
-
-
Save ikbear/1f8f7aed736eced5c025 to your computer and use it in GitHub Desktop.
从 n 个数中选择 m 个的组合(n >= m)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println(f(5, 3)) | |
} | |
func f(n, m int) int { | |
if n <= 0 || m <= 0 { | |
return 0 | |
} | |
if m == 1 { | |
return n | |
} else { | |
return f(n-1, m-1) + f(n-1, m) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
把组合打印出来: