UVa11432 - Busy Programmer

Problem F
Busy Programmer 
Input: 
Standard Input

Output: Standard Output

 

Our famous programmer Gordov Mia (Mr. Donkey) is having a very busy time in his office. His erratic boss has assigned him to two projects (project MICRO & project GOO) at the same time. Consequently, problems have occurred while making a feasible work schedule for him. The boss needs to submit a report to the CEO specifying the schedule of work for all the resources working under him for a period of 2D days.Gordov must work D days on each project. He doesn’t work more than a single project on a particular day. Gordov must finish the work of the project he started earlier (i.e. on the first day of the schedule) first. As the progress of both the projects depends on him, he can not be away from any project for more than G consecutive days. (of course unless a project is already complete.) For example, if D = 3 & G = 2, there can be ten valid schedules,

 

 

Day 1

Day 2

Day 3

Day 4

Day 5

Day 6

1

MICRO

MICRO

GOO

MICRO

GOO

GOO

2

GOO

GOO

MICRO

GOO

MICRO

MICRO

3

MICRO

MICRO

GOO

GOO

MICRO

GOO

4

GOO

GOO

MICRO

MICRO

GOO

MICRO

5

MICRO

GOO

MICRO

MICRO

GOO

GOO

6

GOO

MICRO

GOO

GOO

MICRO

MICRO

7

MICRO

GOO

MICRO

GOO

MICRO

GOO

8

GOO

MICRO

GOO

MICRO

GOO

MICRO

9

MICRO

GOO

GOO

MICRO

MICRO

GOO

10

GOO

MICRO

MICRO

GOO

GOO

MICRO

 

Now, Given D & G, you are to determine the number of possible schedules with the given constraints.

 
Input

There are around 2400 test cases in the input file. Every test case has two non-negative integers, D & G (D,G<=33) on a line by itself. A case with D = G = -1 terminates the input. This case must not be processed.

 

Output

For each test case, print a line in the format “Case x: y” where is the case number & is the number of possible schedules.

 

Sample Input                               Output for Sample Input                                    

3 2

3 1

-1 -1

Case 1: 10

Case 2: 2

太挫了。。。这种题都弹了这么多次!!!

                #include <iostream>
                #include <cstdio>
                #include <cstring>
                #include <vector>
                #include <string>
                #include <algorithm>
                #include <queue>
                using namespace std;
                typedef long long ll;
                ll dp[40][40][3][40];
                int d,g;
                ll dfs(int d1,int d2,int type,int conse){
                    if(d1==0&&d2==0) return type==1;
                    if(d1<0||d2<0) return 0;
                    if(conse<0&&type==0&&d2>0) return 0;
                    if(conse<0&&type==1&&d1>0) return 0;
                    if(dp[d1][d2][type][conse] != -1) return dp[d1][d2][type][conse];
                    ll ans = 0;
                    if(type==0) ans += dfs(d1,d2-1,1,g-1) + dfs(d1-1,d2,0,conse-1);
                    else ans += dfs(d1-1,d2,0,g-1) + dfs(d1,d2-1,1,conse-1);
                    return dp[d1][d2][type][conse] = ans;
                }
                int main(){
                    int T = 1;
                    //freopen("in","r",stdin);
                    while(~scanf("%d%d",&d,&g)&&d!=-1&&g!=-1){
                        printf("Case %d: ",T++);
                        memset(dp,-1,sizeof dp);
                        if(d==0&&g==0) cout<<1<<endl;
                        else  cout<<dfs(d-1,d,0,g-1)*2<<endl;
                    }
                    return 0;
                }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值