给定一个字符串来代表一个员工的考勤纪录,这个纪录仅包含以下两个字符:
'A' : Absent,缺勤
'P' : Present,到场
如果一个员工的考勤纪录中不超过两个'A'(缺勤),那么这个员工会被奖赏。
如果你作为一个员工,想在连续N天的考勤周期中获得奖赏,请问有多少种考勤的组合能够满足要求
给定一个字符串来代表一个员工的考勤纪录,这个纪录仅包含以下两个字符:
'A' : Absent,缺勤
'P' : Present,到场
如果一个员工的考勤纪录中不超过两个'A'(缺勤),那么这个员工会被奖赏。
考勤周期的天数N(正整数)
这N天里能获得奖赏的考勤组合数
3
7
import java.util.Scanner; //46 public class Main { private static int res; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); count(0, 0,n); System.out.println(res); } static void count(int a,int p,int n){ if(a+p>=n){ res++; return ; } if(a<2){ count(a+1, p, n); } count(a, p+1, n); } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int len = input.nextInt(); if (len == 1) System.out.println(1); else if (len == 2) System.out.println(4); else{ System.out.println(len*(len-1)/2+len+1); } } }
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int i = Integer.parseInt(sc.nextLine()); int x1 = 1; int x2 = 0; int x3 = 0; x2 = i; x3 = ((i) * (i-1)) / (2); System.out.println(x1+x2+x3); } }