SCU 4440 Rectangle 递推

frog has a piece of paper divided into n rows and m columns. Today, she would like to draw a rectangle whose perimeter is not greater than k.

Input
The input consists of multiple tests. For each test:
The first line contains 3 integer n,m,k(1≤n,m≤5⋅104,0≤k≤109).

Output
For each test, write 1 integer which denotes the number of ways of drawing.

Sample Input

2 2 6
1 1 0
50000 50000 1000000000

Sample Output

8
0
1562562500625000000

求在NXM的方格中,能画出多少个周长不超过K的矩形。
从第1行到第N行递推,记录每行可行的个数相加。


#include <stdio.h>
#include <climits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <vector>
#include <string>

#define INF 0x3f3f3f3f
#define ll long long
#define Pair pair<int,int>
#define re return

#define getLen(name,index) name[index].size()
#define mem(a,b) memset(a,b,sizeof(a))
#define Make(a,b) make_pair(a,b)
#define Push(num) push_back(num)
#define rep(index,star,finish) for(register int index=star;index<finish;index++)
#define drep(index,finish,star) for(register int index=finish;index>=star;index--)
using namespace std;
const int maxn=5e4+5;

int N,M,K;
void dfs(int r);
ll dp[maxn];
int main(){
    while(~scanf("%d%d%d",&N,&M,&K)){
        ll sum=0;

        ll lim=max(0,min(K/2-1,M));
        mem(dp,0);
        dp[1]=lim*(M+1)*1LL-(1+lim)*lim*1LL/2;
        sum+=dp[1];
        rep(i,2,N+1){
            lim=max(0,min(K/2-i,M));
            dp[i]=dp[i-1]+lim*(M+1)*1LL-(1+lim)*1LL*lim/2;
            sum+=dp[i];
        }
        printf("%lld\n",sum);
    }
    re 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值