惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
小众软件
小众软件
美团技术团队
Martin Fowler
Martin Fowler
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
博客园 - Franky

博客园 - Cheney Shen

如果将 macOS Mojave 降级为 macOS Sierra 或者更低版本 pip源提示“not a trusted or secure host” 解决 Window系统下MongoDB安装及远程访问 Windows下安装appium桌面版和命令行版 Command 'java' not found during running appium sudo npm install -g cnpm --registry=https://registry.npm.taobao.org Pycharm 中错误ImportError: No module named appium CURL并发测试POST和DELETE请求 curl如何发起DELETE/PUT请求?(备忘) Ubuntu 11.10下安装配置Zend Studio 9.0破解版详细步骤 iphone开源汇总(转) iphone开源汇总(转) python中的cursor[备忘] 在main函数执行之前和执行之后执行的方法 Intel苹果电脑Mac+Win+Linux多重系统启动(+公用分区)终极解决方案(备忘) 如何通过一个结构体成员变量的地址找到该结构体的首地址?[备忘] 为特定应用程序关闭恢复窗口功能 [Mac OS X Lion][转] System Events, Key Code and Keystroke from Doug's AppleScripts Mac下Perl脚本如何运行
IGT笔试题,正整数N等于M个不同的正整数之和的问题
Cheney Shen · 2011-10-29 · via 博客园 - Cheney Shen

//

//  

//

//  Created by labuser on 10/29/11.

//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.

//

#include <stdio.h>

#include "time.h"

//#include <sys/time.h>

#define times 7

#define scores 40

#define maxnum 20

void cout(int*, int );

void compute(int, int, int*, int);

int main (int argc, char* argv[])

{

    int score[times] = {0};

    //struct timeval tv;

    //struct timezone tz;

    //gettimeofday(&tv, &tz);

    //int start, end;

    //start = tv.tv_usec;

    //time_t start,end;

    clock_t start, finish;

    double  duration;

    start = clock();

    //start = time(NULL);

    compute(scores, times - 1, score, times);

    finish = clock();

    duration = (double)(finish - start) / CLOCKS_PER_SEC;

    printf("%f seconds\n", duration);

    //end = time(NULL);

    //gettimeofday(&tv, &tz);

    //end = tv.tv_usec;

    //printf("Spend time: %d microseconds\n", end - start);

    //printf("Spend time: %f seconds\n", difftime(end,start));

    return 0;

}

void cout(int* result, int n) {

    int i;

    for (i = n; i > 0; i--) {

        printf("  %d", result[i-1]);

    }

    printf("\n");

}

void compute(int score, int num, int* answer, int m)

{

    if (score < 0 || score > (num+1)*10) {

        return;

    }

    if (num == 0) {

        *(answer + num) = score;

        int n = times - 2;

        while (n >= 0 && *(answer + n) > *(answer + n + 1)) {

            --n;

        } 

        if (n == -1){

            cout(answer, m);

            return;

        }

    }

    int i = answer[times] = 1;

    for(i = answer[num+1]; i <= maxnum; ++i) {

        answer[num] = i;

        compute(score - i, num - 1, answer, m);

    }

}