TLE!!!

记录信息
评测状态    Time Limit Exceeded
题目  P1485 传球游戏
递交时间    2016-07-19 18:51:21
代码语言    C++
评测机 ShadowShore
消耗时间    6607 ms
消耗内存    556 KiB
评测时间    2016-07-19 18:51:30
评测结果
编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #4: Accepted, time = 796 ms, mem = 556 KiB, score = 10
测试数据 #5: TimeLimitExceeded, time = 1187 ms, mem = 548 KiB, score = 0
测试数据 #6: TimeLimitExceeded, time = 1015 ms, mem = 544 KiB, score = 0
测试数据 #7: TimeLimitExceeded, time = 1203 ms, mem = 544 KiB, score = 0
测试数据 #8: TimeLimitExceeded, time = 1203 ms, mem = 544 KiB, score = 0
测试数据 #9: TimeLimitExceeded, time = 1203 ms, mem = 548 KiB, score = 0
TimeLimitExceeded, time = 6607 ms, mem = 556 KiB, score = 50
代码
#include <bits/stdc++.h>
int Ans = 0,n,m;
void solve(int now,int cnt) {
  if (cnt == m) {
    if (now == 1) Ans++;
    return;
  } else if (now == n) {
    solve(1,cnt+1);
    solve(now-1,cnt+1);
  } else if (now == 1) {
    solve(n,cnt+1);
    solve(2,cnt+1);
  } else if (now > 1 && now < n) {
    solve(now+1,cnt+1);
    solve(now-1,cnt+1);
  }
}
int main() {
  scanf("%d%d",&n,&m);
  solve(1,0);
  printf("%d",Ans);
  return 0;
}

5 条评论

  • @ 2016-11-15 20:31:55

    巧了==不过我代码短那么一点点==
    ~~~c++
    #include<iostream>
    using namespace std;
    int m,n,cnt;
    void dfs(int h,int t){
    if(t==0){
    cnt+=!(h^1);return;
    }
    if(h!=1) dfs(h-1,t-1);
    else dfs(n,t-1);
    if(h!=n) dfs(h+1,t-1);
    else dfs(1,t-1);
    }
    int main(){
    cin>>n>>m;
    dfs(1,m);
    cout<<cnt;
    }
    ~~~

  • @ 2016-08-22 22:38:49

    你需要撸爆评测机

  • @ 2016-08-21 14:46:45

    hh我从未见过noip有**爆搜**的题

  • @ 2016-07-20 10:52:54

    你需要递推

  • @ 2016-07-20 08:55:46

    你需要记忆化搜索

  • 1

信息

ID
1485
难度
3
分类
动态规划 点击显示
标签
递交数
4751
已通过
2234
通过率
47%
被复制
14
上传者