给定一个字符串来代表一个员工的考勤纪录,这个纪录仅包含以下两个字符:
'A' : Absent,缺勤
'P' : Present,到场
如果一个员工的考勤纪录中不超过两个'A'(缺勤),那么这个员工会被奖赏。
如果你作为一个员工,想在连续N天的考勤周期中获得奖赏,请问有多少种考勤的组合能够满足要求
给定一个字符串来代表一个员工的考勤纪录,这个纪录仅包含以下两个字符:
'A' : Absent,缺勤
'P' : Present,到场
如果一个员工的考勤纪录中不超过两个'A'(缺勤),那么这个员工会被奖赏。
考勤周期的天数N(正整数)
这N天里能获得奖赏的考勤组合数
3
7
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.print(result(n));
}
private static int result(int n){
if(n ==1){
return 2;
}
int[] table = new int[n+1];
table[1] = 2;
for(int i = 2 ; i<=n ; i++){
table[i] = table[i-1]+i;
}
return table[n];
}
} n = int(input()) print(int(1+n+(n*(n-1))/2) if n>0 else 0)
#include<stdio.h>
int main(){
int n,i,j,m=0;
scanf("%d",&n);
if(n>0) m = 1+n+(n*(n-1))/2;
printf("%d",m);
} using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
//总结目前牛客问题 第一,没有循环输入问题, 第二 有循环输入问题, 第三 输入有多余空格问题 ,第四 中间插入多余空行问题 ....
namespace Test0001
{
class Program
{
public static void Main(string[] args)
{
string line;
while (!string.IsNullOrEmpty(line = Console.ReadLine())) Func(line);
}
public static void Func(string line)
{
int n = int.Parse(line);
Console.WriteLine(1 + n + n * (n - 1) / 2);
}
}
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// 答案就是 c(N,1) + c(N,2) + 1
// c(m,n)
int c(const int m, int n) {
if ((m>>1) < n) {
n = m - n;
}
ll mm = 1;
for (int i=0; i<n; ++i) {
mm *= (m-i);
}
ll nn = 1;
for (int i=1; i<=n; ++i) {
nn *= i;
}
return mm/nn;
}
int main() {
int m = 0;
while (cin >> m) {
int ant = 1;
for (int i=1; i<=2; ++i) {
ant += c(m,i);
}
cout << ant << endl;
}
}
#include<bits/stdc++.h>
using namespace std;
//排列组合函数计算 C(m,n)
int pailie(int m,int n){
long long sum = 1LL;
for(int i=0;i<m;i++){
sum = sum * (n-i);
sum = sum / (i+1);
}
return sum;
}
int main(){
int N;
cin >> N;
cout << pailie(0,N)+pailie(1,N)+pailie(2,N) << endl;
return 0;
} import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = Integer.parseInt(input.nextLine());
if (n == 2)
System.out.println(4);
else
System.out.println(2 * n + (n - 2) * (n - 1) / 2);
}
} import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution7_员工考勤记录 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
/**
* 分三种情况:
* 1.一天不休
* 2.休息一天
* 3.休息两天
* 1.两天连休
* 2.两天分开休息
*/
int sum = 1;//1.情况1
sum += n;//2.休息一天,往 n-1 个 PPP...PPP中插入一个A n-1+1
sum += n - 1;//3.1两天连休
sum += (n - 1) * (n - 2) / 2;//3.2两天分开休
System.out.println(sum);
}
}
/** * 求 n 的阶乘 */ public static int factorial(int n) { if (n > 1) { return n * factorial(n - 1); } return 1; } /** * Cmn 组合数 * m > n * m! / n! * (m - n)! */ public static int compose(int m, int n) { return m >= n? factorial(m) / (factorial(m - n) * factorial(n)) : 0; } /** * Amn 排列数 * m > n * m! / (m-n)! */ public static int arrange(int m, int n) { return m >= n ? factorial(m) / factorial(m - n) : 0; }
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);
}
}
}
/**
* @author like
* @version 1.0
* @date 2020/5/20 14:41
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
System.out.println((n+1)*n/2+1);
}
}