题目
HJ103 Redraiment的走法
实现
package mainimport ("bufio""fmt""os""strconv""strings"
)func main() {scanner := bufio.NewScanner(os.Stdin)nums := make([]int, 0)nums_len:=0dp:=make([]int, 0)for scanner.Scan() {input := scanner.Text()nums_str := strings.Fields(input)if len(nums_str) == 1 {nums_len,_ = strconv.Atoi(nums_str[0])for i:=0;i<nums_len;i++{dp = append(dp, 1) }} else {for _, v := range nums_str {v_int, _ := strconv.Atoi(v)nums = append(nums, v_int)}}}max_result := 1for i,vi:=range nums{for j:=0;j<=i;j++{if nums[j]<vi{dp[i] = max(dp[i], dp[j]+1)max_result = max(dp[i], max_result)}} }fmt.Printf("%d", max_result)
}func max(a,b int)int{if a>b {return a }return b
}